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
25 changes: 21 additions & 4 deletions src/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,28 @@ public function processClose(File $phpcsFile, $stackPtr)
}//end if

if ($difference !== -1 && $difference !== 1) {
if ($tokens[$nextContent]['code'] === T_DOC_COMMENT_OPEN_TAG) {
$next = $phpcsFile->findNext(T_WHITESPACE, ($tokens[$nextContent]['comment_closer'] + 1), null, true);
if ($next !== false && $tokens[$next]['code'] === T_FUNCTION) {
return;
for ($nextSignificant = $nextContent; $nextSignificant < $phpcsFile->numTokens; $nextSignificant++) {
if ($tokens[$nextSignificant]['code'] === T_WHITESPACE) {
continue;
}

if ($tokens[$nextSignificant]['code'] === T_DOC_COMMENT_OPEN_TAG) {
$nextSignificant = $tokens[$nextSignificant]['comment_closer'];
continue;
}

if ($tokens[$nextSignificant]['code'] === T_ATTRIBUTE
&& isset($tokens[$nextSignificant]['attribute_closer']) === true
) {
$nextSignificant = $tokens[$nextSignificant]['attribute_closer'];
continue;
}

break;
}

if ($tokens[$nextSignificant]['code'] === T_FUNCTION) {
return;
}

$error = 'Closing brace of a %s must be followed by a single blank line; found %s';
Expand Down
22 changes: 22 additions & 0 deletions src/Standards/Squiz/Tests/Classes/ClassDeclarationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,25 @@ class Test
readonly class Test
{
}

class TooMuchSpacingBelowClassButShouldNotBeFlaggedWhenNextThingIsFunctionWithAttribute
{
var $x;
}


#[AttributesShouldBeJumpedOver]
function ThisIsFineAndHasAttribute() {}

class TooMuchSpacingBelowClassButShouldNotBeFlaggedWhenNextThingIsFunctionWithDocblockAndAttribute
{
var $x;
}


/**
* No error.
*/
#[AttributesShouldBeJumpedOver]
#[ASecondAttributeShouldBeJumpedOverToo]#[AndAThirdAsWell]
function ThisIsFineAndHasDocblockAndAttribute() {}
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,25 @@ readonly class Test
readonly class Test
{
}

class TooMuchSpacingBelowClassButShouldNotBeFlaggedWhenNextThingIsFunctionWithAttribute
{
var $x;
}


#[AttributesShouldBeJumpedOver]
function ThisIsFineAndHasAttribute() {}

class TooMuchSpacingBelowClassButShouldNotBeFlaggedWhenNextThingIsFunctionWithDocblockAndAttribute
{
var $x;
}


/**
* No error.
*/
#[AttributesShouldBeJumpedOver]
#[ASecondAttributeShouldBeJumpedOverToo]#[AndAThirdAsWell]
function ThisIsFineAndHasDocblockAndAttribute() {}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function getErrorList()
121 => 1,
124 => 2,
128 => 2,
132 => 1,
141 => 1,
];

}//end getErrorList()
Expand Down