From 160dfd71b34972ff87815c3895e4bc38e7851efe Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 25 Nov 2023 11:44:09 +0700 Subject: [PATCH 1/2] [BetterPhpDocParser] Use ORIG_NODE attribute on DoctrineAnnotationDecorator on handle @\ after generic --- .../PhpDocParser/DoctrineAnnotationDecorator.php | 2 +- packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php | 6 +----- .../BetterPhpDocParser/ValueObject/PhpDocAttributeKey.php | 5 ----- .../PhpDocNodeVisitor/CloningPhpDocNodeVisitor.php | 6 +++++- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php b/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php index e9d3c592e48..3e44d8b3117 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php +++ b/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php @@ -276,7 +276,7 @@ private function transformGenericTagValueNodesToDoctrineAnnotationTagValueNodes( $phpDocNode->children[$key] = $spacelessPhpDocTagNode; // require to reprint the generic - $phpDocNode->children[$key]->setAttribute(PhpDocAttributeKey::IS_AFTER_GENERIC, true); + $phpDocNode->children[$key]->value->setAttribute(PhpDocAttributeKey::ORIG_NODE, null); array_splice($phpDocNode->children, $key + 1, 0, $spacelessPhpDocTagNodes); } diff --git a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php index b97e362dbcb..8ed519858e2 100644 --- a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php +++ b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php @@ -342,11 +342,7 @@ private function correctPreviouslyReprintedFirstNode(int $key, StartAndEnd $star private function shouldReprint(PhpDocChildNode $phpDocChildNode): bool { $this->changedPhpDocNodeTraverser->traverse($phpDocChildNode); - if ($this->changedPhpDocNodeVisitor->hasChanged()) { - return true; - } - - return $phpDocChildNode instanceof SpacelessPhpDocTagNode && $phpDocChildNode->getAttribute(PhpDocAttributeKey::IS_AFTER_GENERIC) === true; + return $this->changedPhpDocNodeVisitor->hasChanged(); } private function standardPrintPhpDocChildNode(PhpDocChildNode $phpDocChildNode): string diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocAttributeKey.php b/packages/BetterPhpDocParser/ValueObject/PhpDocAttributeKey.php index dd1cdd9be94..42aee9fe0e1 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocAttributeKey.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocAttributeKey.php @@ -33,9 +33,4 @@ final class PhpDocAttributeKey * @var string */ public const ORIG_NODE = NativePhpDocAttributeKey::ORIG_NODE; - - /** - * @var string - */ - public const IS_AFTER_GENERIC = 'is_after_generic'; } diff --git a/packages/PhpDocParser/PhpDocParser/PhpDocNodeVisitor/CloningPhpDocNodeVisitor.php b/packages/PhpDocParser/PhpDocParser/PhpDocNodeVisitor/CloningPhpDocNodeVisitor.php index 5d2b64841a9..e51e7e528ec 100644 --- a/packages/PhpDocParser/PhpDocParser/PhpDocNodeVisitor/CloningPhpDocNodeVisitor.php +++ b/packages/PhpDocParser/PhpDocParser/PhpDocNodeVisitor/CloningPhpDocNodeVisitor.php @@ -18,7 +18,11 @@ final class CloningPhpDocNodeVisitor extends AbstractPhpDocNodeVisitor public function enterNode(Node $node): Node { $clonedNode = clone $node; - $clonedNode->setAttribute(PhpDocAttributeKey::ORIG_NODE, $node); + + if (! $clonedNode->hasAttribute(PhpDocAttributeKey::ORIG_NODE)) { + $clonedNode->setAttribute(PhpDocAttributeKey::ORIG_NODE, $node); + } + return $clonedNode; } } From e2f7a41cd4feb1e441d798e3edb0d87a56a5b3a9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 25 Nov 2023 11:50:26 +0700 Subject: [PATCH 2/2] cs fix --- packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php index 8ed519858e2..88ef57acd07 100644 --- a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php +++ b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php @@ -16,7 +16,6 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\PhpDocParser\Lexer\Lexer; -use Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocNodeVisitor\ChangedPhpDocNodeVisitor; use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;