diff --git a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php index faab10f38d2..2a639f1e105 100644 --- a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php +++ b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php @@ -4,6 +4,7 @@ namespace Rector\TypeDeclarationDocblocks\Rector\ClassMethod; +use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; @@ -85,6 +86,11 @@ public function getNodeTypes(): array */ public function refactor(Node $node): null|ClassMethod|Function_ { + // a @return tag can only live in a docblock; skip nodes without one + if (!$node->getDocComment() instanceof Doc) { + return null; + } + $phpDocInfo = $this->phpDocInfoFactory->createFromNode($node); if (! $phpDocInfo instanceof PhpDocInfo) { return null;