Skip to content

Commit b445ac0

Browse files
committed
some fixes
1 parent 6ff7064 commit b445ac0

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/Rule/NotShouldPhpdocReturnIfExistTypeHint.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,22 @@ public function processNode(Node $node, Scope $scope): array
4646
$methods = $reflection->getMethods();
4747

4848
foreach ($methods as $method) {
49-
$returnType = $method->getReturnType()?->getName();
49+
if (str_starts_with($method->getName(), '__')) {
50+
continue;
51+
}
52+
5053
$doc = (string)$method->getDocComment();
54+
if ($doc === '') {
55+
continue;
56+
}
57+
58+
59+
$returnType = $method->getReturnType();
60+
if ($returnType === null || !method_exists($returnType, 'getName')) {
61+
return [];
62+
}
5163

64+
$returnTypeName = $returnType->getName();
5265
$tokens = new TokenIterator($this->phpDocLexer->tokenize($doc));
5366
$text = $this->parser->parse($tokens);
5467
foreach ($text->getTags() as $tag) {
@@ -57,8 +70,9 @@ public function processNode(Node $node, Scope $scope): array
5770
}
5871
if ($tag->value instanceof ReturnTagValueNode) {
5972
$value = $tag->value->type->name;
60-
if ($value === $returnType) {
61-
return ['PhpDoc attribute @return can be remove'];
73+
if ($value == $returnTypeName
74+
&& $reflection->getName() === $method->getBetterReflection()->getLocatedSource()->getName()) {
75+
return ['PhpDoc attribute @return for method ' . $method->getName() . ' can be remove'];
6276
}
6377
}
6478
}

0 commit comments

Comments
 (0)