Skip to content

Commit ff00744

Browse files
committed
Generic/UselessOverridingMethod: remove $next === false checks
Early on in the sniff code, it is checked if the method has a scope opener (which is never true if there is no scope closer). So there always will be at least one token after the scope opener, the scope closer. This means that `$next === false` checks are not necessary. `$next` will never be false. To be extra careful, a check to confirm that the scope closer is present was added to the beginning of the sniff.
1 parent bf351dd commit ff00744

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function process(File $phpcsFile, $stackPtr)
5656
$token = $tokens[$stackPtr];
5757

5858
// Skip function without body.
59-
if (isset($token['scope_opener']) === false) {
59+
if (isset($token['scope_opener'], $token['scope_closer']) === false) {
6060
return;
6161
}
6262

@@ -93,23 +93,23 @@ public function process(File $phpcsFile, $stackPtr)
9393
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
9494

9595
// Skip for invalid code.
96-
if ($next === false || $tokens[$next]['code'] !== T_DOUBLE_COLON) {
96+
if ($tokens[$next]['code'] !== T_DOUBLE_COLON) {
9797
return;
9898
}
9999

100100
// Find next non empty token index, should be the parent method name.
101101
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
102102

103103
// Skip for invalid code or other method.
104-
if ($next === false || strcasecmp($tokens[$next]['content'], $methodName) !== 0) {
104+
if (strcasecmp($tokens[$next]['content'], $methodName) !== 0) {
105105
return;
106106
}
107107

108108
// Find next non empty token index, should be the open parenthesis.
109109
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
110110

111111
// Skip for invalid code.
112-
if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS || isset($tokens[$next]['parenthesis_closer']) === false) {
112+
if ($tokens[$next]['code'] !== T_OPEN_PARENTHESIS || isset($tokens[$next]['parenthesis_closer']) === false) {
113113
return;
114114
}
115115

@@ -134,7 +134,7 @@ public function process(File $phpcsFile, $stackPtr)
134134
}//end for
135135

136136
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
137-
if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) {
137+
if ($tokens[$next]['code'] !== T_SEMICOLON) {
138138
return;
139139
}
140140

0 commit comments

Comments
 (0)