Skip to content

Commit

Permalink
Merge branch 'php-8.0/squiz-blockcomment-support-attributes' of https…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jul 28, 2021
2 parents 0108d40 + 39dd4b7 commit 5f6d9ae
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,18 @@ public function process(File $phpcsFile, $stackPtr)
// If this is a function/class/interface doc block comment, skip it.
// We are only interested in inline doc block comments.
if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
$nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
$ignore = [
$nextToken = $stackPtr;
do {
$nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextToken + 1), null, true);
if ($tokens[$nextToken]['code'] === T_ATTRIBUTE) {
$nextToken = $tokens[$nextToken]['attribute_closer'];
continue;
}

break;
} while (true);

$ignore = [
T_CLASS => true,
T_INTERFACE => true,
T_TRAIT => true,
Expand Down
16 changes: 16 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,19 @@ $contentToEcho
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
*/
$contentToEcho

/**
* Comment should be ignored, even though there is an attribute between the docblock and the class declaration.
*/

#[AttributeA]

final class MyClass
{
/**
* Comment should be ignored, even though there is an attribute between the docblock and the function declaration
*/
#[AttributeA]
#[AttributeB]
final public function test() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,19 @@ $contentToEcho
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
*/
$contentToEcho

/**
* Comment should be ignored, even though there is an attribute between the docblock and the class declaration.
*/

#[AttributeA]

final class MyClass
{
/**
* Comment should be ignored, even though there is an attribute between the docblock and the function declaration
*/
#[AttributeA]
#[AttributeB]
final public function test() {}
}

0 comments on commit 5f6d9ae

Please sign in to comment.