Skip to content

Commit

Permalink
Fix some quality flaws (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandalbosco authored and vilchik-elena committed Oct 24, 2016
1 parent 02b5c14 commit cf93dcd
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public void visitScript(ScriptTree tree) {
super.visitScript(tree);

if ((nbClass + nbInterface) > 1) {
String message = String.format(MESSAGE,
nbClass > 0 ? (nbClass + " independent classes ") : "",
nbClass > 0 && nbInterface > 0 ? "and " : "",
nbInterface > 0 ? (nbInterface + " independent interfaces ") : "");
String independentClasses = nbClass > 0 ? (nbClass + " independent classes ") : "";
String and = nbClass > 0 && nbInterface > 0 ? "and " : "";
String indendentInterfaces = nbInterface > 0 ? (nbInterface + " independent interfaces ") : "";
String message = String.format(MESSAGE, independentClasses, and, indendentInterfaces);

int cost = nbClass + nbInterface - 1;
context().newFileIssue(this, message).cost(cost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class PHP5DeprecatedFunctionUsageCheck extends FunctionUsageCheck {
private static final String MESSAGE_SET_LOCAL_ARG = "Use the \"%s\" constant instead of a string literal.";
private static final String MESSAGE_WITH_REPLACEMENT = "Replace this \"%s()\" call with a call to \"%s\".";
private static final String MESSAGE_WITHOUT_REPLACEMENT = "Remove this \"%s()\" call.";
private static final String SESSION = "$_SESSION";

private static final ImmutableMap<String, String> NEW_BY_DEPRECATED_FUNCTIONS = ImmutableMap.<String, String>builder()
.put("call_user_method", "call_user_func()")
Expand All @@ -49,9 +50,9 @@ public class PHP5DeprecatedFunctionUsageCheck extends FunctionUsageCheck {
.put("eregi_replace", "preg_replace() with 'i' modifier")
.put("set_magic_quotes_runtime", "")
.put("magic_quotes_runtime", "")
.put("session_register", "$_SESSION")
.put("session_unregister", "$_SESSION")
.put("session_is_registered", "$_SESSION")
.put("session_register", SESSION)
.put("session_unregister", SESSION)
.put("session_is_registered", SESSION)
.put("set_socket_blocking", "stream_set_blocking")
.put("split", "preg_split")
.put("spliti", "preg_split")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public class TooManyFieldsInClassCheck extends PHPVisitorCheck {

@RuleProperty(
key = "countNonpublicFields",
type = "BOOLEAN",
defaultValue = "" + DEFAULT_COUNT_NON_PUBLIC)
defaultValue = "" + DEFAULT_COUNT_NON_PUBLIC,
type = "BOOLEAN")
boolean countNonpublicFields = DEFAULT_COUNT_NON_PUBLIC;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class TooManyMethodsInClassCheck extends PHPVisitorCheck {

@RuleProperty(
key = "countNonpublicMethods",
type = "BOOLEAN",
defaultValue = "" + DEFAULT_NON_PUBLIC)
defaultValue = "" + DEFAULT_NON_PUBLIC,
type = "BOOLEAN")
public boolean countNonpublicMethods = DEFAULT_NON_PUBLIC;


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SonarQube PHP Plugin
* Copyright (C) 2010-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.php.checks.utils;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SonarQube PHP Plugin
* Copyright (C) 2010-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.plugins.php.api.tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SonarQube PHP Plugin
* Copyright (C) 2010-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.plugins.php.phpunit;

import javax.annotation.ParametersAreNonnullByDefault;

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SonarQube PHP Plugin
* Copyright (C) 2010-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.plugins.php.phpunit.xml;

import javax.annotation.ParametersAreNonnullByDefault;

0 comments on commit cf93dcd

Please sign in to comment.