Skip to content

Commit 5f6d9ae

Browse files
committed
Merge branch 'php-8.0/squiz-blockcomment-support-attributes' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 0108d40 + 39dd4b7 commit 5f6d9ae

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,18 @@ public function process(File $phpcsFile, $stackPtr)
6969
// If this is a function/class/interface doc block comment, skip it.
7070
// We are only interested in inline doc block comments.
7171
if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
72-
$nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
73-
$ignore = [
72+
$nextToken = $stackPtr;
73+
do {
74+
$nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextToken + 1), null, true);
75+
if ($tokens[$nextToken]['code'] === T_ATTRIBUTE) {
76+
$nextToken = $tokens[$nextToken]['attribute_closer'];
77+
continue;
78+
}
79+
80+
break;
81+
} while (true);
82+
83+
$ignore = [
7484
T_CLASS => true,
7585
T_INTERFACE => true,
7686
T_TRAIT => true,

src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,19 @@ $contentToEcho
272272
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
273273
*/
274274
$contentToEcho
275+
276+
/**
277+
* Comment should be ignored, even though there is an attribute between the docblock and the class declaration.
278+
*/
279+
280+
#[AttributeA]
281+
282+
final class MyClass
283+
{
284+
/**
285+
* Comment should be ignored, even though there is an attribute between the docblock and the function declaration
286+
*/
287+
#[AttributeA]
288+
#[AttributeB]
289+
final public function test() {}
290+
}

src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc.fixed

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,19 @@ $contentToEcho
274274
* No blank line allowed above the comment if it's the first non-empty token after a PHP open tag.
275275
*/
276276
$contentToEcho
277+
278+
/**
279+
* Comment should be ignored, even though there is an attribute between the docblock and the class declaration.
280+
*/
281+
282+
#[AttributeA]
283+
284+
final class MyClass
285+
{
286+
/**
287+
* Comment should be ignored, even though there is an attribute between the docblock and the function declaration
288+
*/
289+
#[AttributeA]
290+
#[AttributeB]
291+
final public function test() {}
292+
}

0 commit comments

Comments
 (0)