From 40fb472626c5af7f2015b8d2afc28b488a03376e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 11 Oct 2026 19:22:52 +0200 Subject: [PATCH 1/2] [perf] Skip NarrowArrayCollectionUnionReturnDocblockRector for nodes without a docblock The rule subscribes to ClassMethod and Function_ and built a PhpDocInfo for every node to narrow a union @return tag. The tag only exists in a docblock; guard with getDocComment(). Without one there is no @return to narrow, so behaviour is unchanged. --- .../NarrowArrayCollectionUnionReturnDocblockRector.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php index faab10f38d2..ec5a654c141 100644 --- a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php +++ b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php @@ -85,6 +85,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() === null) { + return null; + } + $phpDocInfo = $this->phpDocInfoFactory->createFromNode($node); if (! $phpDocInfo instanceof PhpDocInfo) { return null; From 0b86b179c66cf82b50ef61b2a3ba2ea1ffeeead6 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 11 Oct 2026 17:24:02 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- .../NarrowArrayCollectionUnionReturnDocblockRector.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/NarrowArrayCollectionUnionReturnDocblockRector.php index ec5a654c141..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_; @@ -86,7 +87,7 @@ 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() === null) { + if (!$node->getDocComment() instanceof Doc) { return null; }