Skip to content

Commit

Permalink
Universal/SeparateFunctionsFromOO: simplify skipping the rest of the …
Browse files Browse the repository at this point in the history
…file

This commit updates the sniff to use `return $phpcsFile->numTokens` instead of `return ($phpcsFile->numTokens + 1)`.

If a sniff file contains 50 tokens, the last `$stackPtr` will be 49, so returning `50` will already get us passed the end of the token stack and the `+ 1` is redundant.

Includes minor fix to the return type as the method never returns `void`.
  • Loading branch information
jrfnl committed Nov 8, 2024
1 parent 2bd085a commit 7b88c12
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Universal/Sniffs/Files/SeparateFunctionsFromOOSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public function register()
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
* @return int Integer stack pointer to skip forward.
*/
public function process(File $phpcsFile, $stackPtr)
{
Expand Down Expand Up @@ -185,6 +184,6 @@ public function process(File $phpcsFile, $stackPtr)
}

// Ignore the rest of the file.
return ($phpcsFile->numTokens + 1);
return $phpcsFile->numTokens;
}
}

0 comments on commit 7b88c12

Please sign in to comment.