Skip to content

Commit 7ccf2bf

Browse files
committed
Generic/CamelCapsFunctionName: don't hide one message behind another
1 parent e9e7b57 commit 7ccf2bf

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
110110
// Is this a magic method. i.e., is prefixed with "__" ?
111111
if (preg_match('|^__[^_]|', $methodName) !== 0) {
112112
$magicPart = strtolower(substr($methodName, 2));
113-
if (isset($this->magicMethods[$magicPart]) === false
114-
&& isset($this->methodsDoubleUnderscore[$magicPart]) === false
113+
if (isset($this->magicMethods[$magicPart]) === true
114+
|| isset($this->methodsDoubleUnderscore[$magicPart]) === true
115115
) {
116-
$error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
117-
$phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
116+
return;
118117
}
119118

120-
return;
119+
$error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
120+
$phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
121121
}
122122

123123
// PHP4 constructors are allowed to break our rules.
@@ -178,12 +178,12 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
178178
// Is this a magic function. i.e., it is prefixed with "__".
179179
if (preg_match('|^__[^_]|', $functionName) !== 0) {
180180
$magicPart = strtolower(substr($functionName, 2));
181-
if (isset($this->magicFunctions[$magicPart]) === false) {
182-
$error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
183-
$phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData);
181+
if (isset($this->magicFunctions[$magicPart]) === true) {
182+
return;
184183
}
185184

186-
return;
185+
$error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
186+
$phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData);
187187
}
188188

189189
// Ignore first underscore in functions prefixed with "_".

src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getErrorList()
4040
31 => 1,
4141
50 => 1,
4242
52 => 1,
43-
53 => 1,
43+
53 => 2,
4444
57 => 1,
4545
58 => 1,
4646
59 => 1,
@@ -52,16 +52,16 @@ public function getErrorList()
5252
65 => 1,
5353
66 => 1,
5454
67 => 1,
55-
68 => 1,
55+
68 => 2,
5656
69 => 1,
5757
71 => 1,
5858
72 => 1,
59-
73 => 1,
59+
73 => 2,
6060
74 => 1,
6161
118 => 1,
6262
144 => 1,
6363
146 => 1,
64-
147 => 1,
64+
147 => 2,
6565
];
6666

6767
return $errors;

0 commit comments

Comments
 (0)