Skip to content

Commit db0f06a

Browse files
committed
InlineDocCommentDeclarationSniff: Fixed false positive
1 parent 2a290b6 commit db0f06a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

SlevomatCodingStandard/Sniffs/Commenting/InlineDocCommentDeclarationSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use const T_AS;
1717
use const T_ATTRIBUTE;
1818
use const T_CLOSURE;
19+
use const T_COALESCE_EQUAL;
1920
use const T_COMMENT;
2021
use const T_DOC_COMMENT_OPEN_TAG;
2122
use const T_EQUAL;
@@ -458,7 +459,7 @@ private function isAssignment(File $phpcsFile, int $pointer): bool
458459
return $tokens[$pointerBeforeVariable]['code'] === T_STATIC;
459460
}
460461

461-
return $tokens[$pointerAfterVariable]['code'] === T_EQUAL;
462+
return in_array($tokens[$pointerAfterVariable]['code'], [T_EQUAL, T_COALESCE_EQUAL], true);
462463
}
463464

464465
}

tests/Sniffs/Commenting/data/noInvalidInlineDocCommentDeclarations.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public function __construct()
125125
/** @var int $tt */
126126
array_map(fn ($tt): int => $tt, []);
127127

128+
/** @var int $u */
129+
$u ??= 10;
130+
128131
/** @var callable(string) : int $callable1 */
129132
$callable1 = static function(string $x) : int{return 1;};
130133
/** @var callable(string): int $callable2 */

0 commit comments

Comments
 (0)