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
16 changes: 10 additions & 6 deletions src/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ public function process(File $phpcsFile, $stackPtr)
// We are only interested in inline doc block comments, which are
// not allowed.
if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
$nextToken = $phpcsFile->findNext(
Tokens::$emptyTokens,
($stackPtr + 1),
null,
true
);
$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,
Expand Down
16 changes: 16 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ if ($foo) {
// another comment here.
$foo++;

/**
* 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() {}
}

/*
* N.B.: The below test line must be the last test in the file.
* Testing that a new line after an inline comment when it's the last non-whitespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ if ($foo) {
// another comment here.
$foo++;

/**
* 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() {}
}

/*
* N.B.: The below test line must be the last test in the file.
* Testing that a new line after an inline comment when it's the last non-whitespace
Expand Down