Skip to content

Commit 1071c98

Browse files
committed
SlevomatCodingStandard.TypeHints.ReturnTypeHint: Fixed false positive
1 parent 266a906 commit 1071c98

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

SlevomatCodingStandard/Helpers/DocCommentHelper.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,17 @@ public static function hasInheritdocAnnotation(File $phpcsFile, int $pointer): b
131131
}
132132

133133
foreach ($parsedDocComment->getNode()->children as $child) {
134-
if ($child instanceof PhpDocTextNode && stripos($child->text, '{@inheritdoc}') !== false) {
135-
return true;
134+
if ($child instanceof PhpDocTagNode) {
135+
if (strtolower($child->name) === '@inheritdoc') {
136+
return true;
137+
}
138+
139+
if (stripos((string) $child->value, '{@inheritdoc}') !== false) {
140+
return true;
141+
}
136142
}
137143

138-
if ($child instanceof PhpDocTagNode && strtolower($child->name) === '@inheritdoc') {
144+
if ($child instanceof PhpDocTextNode && stripos($child->text, '{@inheritdoc}') !== false) {
139145
return true;
140146
}
141147
}

tests/Sniffs/TypeHints/data/returnTypeHintNoErrors.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ private function hasInheritdocAnnotation()
2121
return true;
2222
}
2323

24+
/**
25+
* @deprecated
26+
*
27+
* {@inheritdoc}
28+
*/
29+
private function hasInheritdocAnnotationWithOtherAnnotation()
30+
{
31+
return true;
32+
}
33+
2434
/**
2535
* Description.
2636
*

0 commit comments

Comments
 (0)