Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
28 changes: 28 additions & 0 deletions src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
} ?>

<?php
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,31 @@ class ClassWithMultiLineImplementsAndCommentOnSameLineAsInterfaceName implements
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
{
} ?>

<?php
2 changes: 2 additions & 0 deletions src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function getErrorList()
282 => 1,
310 => 1,
316 => 1,
324 => 1,
344 => 1,
];

}//end getErrorList()
Expand Down