diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector.php index fba40a37222..ce857108361 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector.php @@ -4,6 +4,7 @@ namespace Rector\DeadCode\Rector\ClassMethod; +use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Identifier; use PhpParser\Node\Name; @@ -92,6 +93,11 @@ public function refactor(Node $node): ?Node return null; } + // a duplicated @return tag can only live in a docblock; skip before resolving reflection + if (!$node->getDocComment() instanceof Doc) { + return null; + } + $classReflection = $this->reflectionResolver->resolveClassReflection($node); if (! $classReflection instanceof ClassReflection) { return null;