Skip to content

Commit 04da558

Browse files
committed
PSR2/ClassDeclaration: remove some redundant code [1]
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.
1 parent e5e3b08 commit 04da558

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ public function processClose(File $phpcsFile, $stackPtr)
525525
$ignoreTokens[] = T_WHITESPACE;
526526
$ignoreTokens[] = T_COMMENT;
527527
$ignoreTokens[] = T_SEMICOLON;
528-
$ignoreTokens[] = T_COMMA;
529528
$nextContent = $phpcsFile->findNext($ignoreTokens, ($closeBrace + 1), null, true);
530529
if ($tokens[$nextContent]['content'] !== $phpcsFile->eolChar
531530
&& $tokens[$nextContent]['line'] === $tokens[$closeBrace]['line']

src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,10 @@ interface ClassBraceNotOnLineByItselfTrailingCommentIsAllowed
331331
trait ClassBraceNotOnLineByItselfTrailingAnnotationIsAllowed
332332
{
333333
} // phpcs:ignore Stnd.Cat.Sniff -- this comment is also allowed.
334+
335+
// Issue squizlabs/PHP_CodeSniffer#2621 - fix was superseded by fix for #2678.
336+
$foo->bar(
337+
new class implements Bar {
338+
// ...
339+
},
340+
);

src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,10 @@ interface ClassBraceNotOnLineByItselfTrailingCommentIsAllowed
320320
trait ClassBraceNotOnLineByItselfTrailingAnnotationIsAllowed
321321
{
322322
} // phpcs:ignore Stnd.Cat.Sniff -- this comment is also allowed.
323+
324+
// Issue squizlabs/PHP_CodeSniffer#2621 - fix was superseded by fix for #2678.
325+
$foo->bar(
326+
new class implements Bar {
327+
// ...
328+
},
329+
);

0 commit comments

Comments
 (0)