diff --git a/rules/Renaming/NodeManipulator/ClassRenamer.php b/rules/Renaming/NodeManipulator/ClassRenamer.php index f387d87dc48..7f746789b23 100644 --- a/rules/Renaming/NodeManipulator/ClassRenamer.php +++ b/rules/Renaming/NodeManipulator/ClassRenamer.php @@ -100,6 +100,11 @@ public function renameNode(Node $node, array $oldToNewClasses): ?Node */ private function refactorPhpDoc(Node $node, array $oldToNewTypes, array $oldToNewClasses): void { + if (!$this->hasOriginalNodePhpDoc($node)) { + // no need to create empty PHPDoc nodes and traverse over those, if the code had no PHPDoc in the first place + return; + } + $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); if (! $phpDocInfo->hasByTypes(NodeTypes::TYPE_AWARE_NODES) && ! $phpDocInfo->hasByAnnotationClasses( NodeTypes::TYPE_AWARE_DOCTRINE_ANNOTATION_CLASSES @@ -487,4 +492,17 @@ private function resolveOldToNewClassCallbacks(Node $node, array $oldToNewClasse { return [...$oldToNewClasses, ...$this->renameClassCallbackHandler->getOldToNewClassesFromNode($node)]; } + + /** + * Checks whether the original node has any PHPDoc comments. + */ + private function hasOriginalNodePhpDoc(Node $node): bool + { + $origNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE); + if ($origNode instanceof Node && $origNode->getDocComment() === null && $origNode->getComments() === []) { + return false; + } + + return true; + } }