Skip to content

Commit 922e946

Browse files
committed
InlineDocCommentDeclarationSniff: Fixed false positive
1 parent 35e0235 commit 922e946

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

SlevomatCodingStandard/Sniffs/Commenting/InlineDocCommentDeclarationSniff.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use function substr;
1515
use function trim;
1616
use const T_AS;
17+
use const T_ATTRIBUTE;
1718
use const T_CLOSURE;
1819
use const T_COMMENT;
1920
use const T_DOC_COMMENT_OPEN_TAG;
@@ -71,6 +72,13 @@ public function process(File $phpcsFile, $commentOpenPointer): void
7172

7273
$pointerAfterCommentClosePointer = TokenHelper::findNextEffective($phpcsFile, $commentClosePointer + 1);
7374
if ($pointerAfterCommentClosePointer !== null) {
75+
if ($tokens[$pointerAfterCommentClosePointer]['code'] === T_ATTRIBUTE) {
76+
$pointerAfterCommentClosePointer = TokenHelper::findNextEffective(
77+
$phpcsFile,
78+
$tokens[$pointerAfterCommentClosePointer]['attribute_closer'] + 1
79+
);
80+
}
81+
7482
if (in_array($tokens[$pointerAfterCommentClosePointer]['code'], [T_PRIVATE, T_PROTECTED, T_PUBLIC], true)) {
7583
return;
7684
}

tests/Sniffs/Commenting/data/noInvalidInlineDocCommentDeclarations.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<?php // lint >= 7.4
1+
<?php // lint >= 8.0
22

33
class Foo
44
{
55

66
/** @var string */
77
private $foo;
88

9+
/** @var string */
10+
#[Assert\NotBlank]
11+
private $foo2;
12+
913
/** @var string */
1014
static public $static1;
1115

0 commit comments

Comments
 (0)