Skip to content

Commit

Permalink
PSR2/ClassDeclaration: remove some redundant code [2]
Browse files Browse the repository at this point in the history
In the original version of the sniff, only comments tokens after the close brace were ignored for the `CloseBraceSameLine` check.

Since then the sniff has received numerous changes improving on that code to prevent false positives.

Once such change was made in response to issue squizlabs/PHP_CodeSniffer 689, the fix adding ignoring for whitespace tokens to the code block.

This makes the `$tokens[$nextContent]['content'] !== $phpcsFile->eolChar` check redundant as that condition can now never be true anymore (as it could only match on `T_WHITESPACE` tokens and those are now ignored).

This change is covered by the tests previously added.
  • Loading branch information
jrfnl committed Jul 20, 2024
1 parent 04da558 commit 1d4c9d2
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,7 @@ public function processClose(File $phpcsFile, $stackPtr)
$ignoreTokens[] = T_COMMENT;
$ignoreTokens[] = T_SEMICOLON;
$nextContent = $phpcsFile->findNext($ignoreTokens, ($closeBrace + 1), null, true);
if ($tokens[$nextContent]['content'] !== $phpcsFile->eolChar
&& $tokens[$nextContent]['line'] === $tokens[$closeBrace]['line']
) {
if ($tokens[$nextContent]['line'] === $tokens[$closeBrace]['line']) {
$type = strtolower($tokens[$stackPtr]['content']);
$error = 'Closing %s brace must be on a line by itself';
$data = [$type];
Expand Down

0 comments on commit 1d4c9d2

Please sign in to comment.