Skip to content

Commit cf93dcd

Browse files
ivandalboscovilchik-elena
authored andcommitted
Fix some quality flaws (#142)
1 parent 02b5c14 commit cf93dcd

File tree

8 files changed

+102
-11
lines changed

8 files changed

+102
-11
lines changed

php-checks/src/main/java/org/sonar/php/checks/MoreThanOneClassInFileCheck.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public void visitScript(ScriptTree tree) {
5454
super.visitScript(tree);
5555

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

6262
int cost = nbClass + nbInterface - 1;
6363
context().newFileIssue(this, message).cost(cost);

php-checks/src/main/java/org/sonar/php/checks/PHP5DeprecatedFunctionUsageCheck.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class PHP5DeprecatedFunctionUsageCheck extends FunctionUsageCheck {
3737
private static final String MESSAGE_SET_LOCAL_ARG = "Use the \"%s\" constant instead of a string literal.";
3838
private static final String MESSAGE_WITH_REPLACEMENT = "Replace this \"%s()\" call with a call to \"%s\".";
3939
private static final String MESSAGE_WITHOUT_REPLACEMENT = "Remove this \"%s()\" call.";
40+
private static final String SESSION = "$_SESSION";
4041

4142
private static final ImmutableMap<String, String> NEW_BY_DEPRECATED_FUNCTIONS = ImmutableMap.<String, String>builder()
4243
.put("call_user_method", "call_user_func()")
@@ -49,9 +50,9 @@ public class PHP5DeprecatedFunctionUsageCheck extends FunctionUsageCheck {
4950
.put("eregi_replace", "preg_replace() with 'i' modifier")
5051
.put("set_magic_quotes_runtime", "")
5152
.put("magic_quotes_runtime", "")
52-
.put("session_register", "$_SESSION")
53-
.put("session_unregister", "$_SESSION")
54-
.put("session_is_registered", "$_SESSION")
53+
.put("session_register", SESSION)
54+
.put("session_unregister", SESSION)
55+
.put("session_is_registered", SESSION)
5556
.put("set_socket_blocking", "stream_set_blocking")
5657
.put("split", "preg_split")
5758
.put("spliti", "preg_split")

php-checks/src/main/java/org/sonar/php/checks/TooManyFieldsInClassCheck.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public class TooManyFieldsInClassCheck extends PHPVisitorCheck {
4949

5050
@RuleProperty(
5151
key = "countNonpublicFields",
52-
type = "BOOLEAN",
53-
defaultValue = "" + DEFAULT_COUNT_NON_PUBLIC)
52+
defaultValue = "" + DEFAULT_COUNT_NON_PUBLIC,
53+
type = "BOOLEAN")
5454
boolean countNonpublicFields = DEFAULT_COUNT_NON_PUBLIC;
5555

5656
@Override

php-checks/src/main/java/org/sonar/php/checks/TooManyMethodsInClassCheck.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public class TooManyMethodsInClassCheck extends PHPVisitorCheck {
4848

4949
@RuleProperty(
5050
key = "countNonpublicMethods",
51-
type = "BOOLEAN",
52-
defaultValue = "" + DEFAULT_NON_PUBLIC)
51+
defaultValue = "" + DEFAULT_NON_PUBLIC,
52+
type = "BOOLEAN")
5353
public boolean countNonpublicMethods = DEFAULT_NON_PUBLIC;
5454

5555

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

0 commit comments

Comments
 (0)