Skip to content

Commit

Permalink
PSR2/ClassDeclaration: remove some redundant code [1]
Browse files Browse the repository at this point in the history
Issue squizlabs/PHP_CodeSniffer 2621 added the `T_COMMA` token to the `$ignoreTokens` (without adding a test) to prevent a false positive for a anonymous class declaration nested within a function call.
That fix was later superseded by another fix for basically the same issue via squizlabs/PHP_CodeSniffer#2678, which excluded anonymous classes completely from the `CloseBraceSameLine` check.

This commit adds the test case from squizlabs/PHP_CodeSniffer 2621 and removed the redundant `T_COMMA` token as the test now confirms it is no longer needed.
  • Loading branch information
jrfnl committed Jul 20, 2024
1 parent e5e3b08 commit 04da558
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ public function processClose(File $phpcsFile, $stackPtr)
$ignoreTokens[] = T_WHITESPACE;
$ignoreTokens[] = T_COMMENT;
$ignoreTokens[] = T_SEMICOLON;
$ignoreTokens[] = T_COMMA;
$nextContent = $phpcsFile->findNext($ignoreTokens, ($closeBrace + 1), null, true);
if ($tokens[$nextContent]['content'] !== $phpcsFile->eolChar
&& $tokens[$nextContent]['line'] === $tokens[$closeBrace]['line']
Expand Down
7 changes: 7 additions & 0 deletions src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,10 @@ interface ClassBraceNotOnLineByItselfTrailingCommentIsAllowed
trait ClassBraceNotOnLineByItselfTrailingAnnotationIsAllowed
{
} // phpcs:ignore Stnd.Cat.Sniff -- this comment is also allowed.

// Issue squizlabs/PHP_CodeSniffer#2621 - fix was superseded by fix for #2678.
$foo->bar(
new class implements Bar {
// ...
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,10 @@ interface ClassBraceNotOnLineByItselfTrailingCommentIsAllowed
trait ClassBraceNotOnLineByItselfTrailingAnnotationIsAllowed
{
} // phpcs:ignore Stnd.Cat.Sniff -- this comment is also allowed.

// Issue squizlabs/PHP_CodeSniffer#2621 - fix was superseded by fix for #2678.
$foo->bar(
new class implements Bar {
// ...
},
);

0 comments on commit 04da558

Please sign in to comment.