diff --git a/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php b/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php index 3325459ae2..887c552edc 100644 --- a/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php +++ b/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php @@ -525,11 +525,8 @@ 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'] - ) { + 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]; diff --git a/src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc b/src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc index 144eef8fe3..1df40d5149 100644 --- a/src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc +++ b/src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc @@ -316,3 +316,31 @@ class ClassWithMultiLineImplementsAndCommentOnSameLineAsInterfaceName implements /* Comment. */ AnotherInterface { } + +// Verify the `CloseBraceSameLine` error code is thrown when expected. +class ClassBraceNotOnLineByItselfError +{ + public $prop; +} $foo = new ClassBraceNotOnLineByItselfError; + +interface ClassBraceNotOnLineByItselfTrailingCommentIsAllowed +{ + public function myMethod(); +} //end interface -- this comment is allowed. + +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 { + // ... + }, +); + +enum BraceNotOnLineByItselfCloseTagError +{ +} ?> + +bar( + new class implements Bar { + // ... + }, +); + +enum BraceNotOnLineByItselfCloseTagError +{ +} ?> + + 1, 310 => 1, 316 => 1, + 324 => 1, + 344 => 1, ]; }//end getErrorList()