Skip to content

Commit

Permalink
Generic/UselessOverridingMethod: remove $next === false checks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rodrigoprimo authored and jrfnl committed Mar 4, 2024
1 parent f4d815e commit f38ea41
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function process(File $phpcsFile, $stackPtr)
$token = $tokens[$stackPtr];

// Skip function without body.
if (isset($token['scope_opener']) === false) {
if (isset($token['scope_opener'], $token['scope_closer']) === false) {
return;
}

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

// Skip for invalid code.
if ($next === false || $tokens[$next]['code'] !== T_DOUBLE_COLON) {
if ($tokens[$next]['code'] !== T_DOUBLE_COLON) {
return;
}

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

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

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

// Skip for invalid code.
if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS || isset($tokens[$next]['parenthesis_closer']) === false) {
if ($tokens[$next]['code'] !== T_OPEN_PARENTHESIS || isset($tokens[$next]['parenthesis_closer']) === false) {
return;
}

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

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

Expand Down

0 comments on commit f38ea41

Please sign in to comment.