Skip to content

Commit

Permalink
[BetterPhpDocParser] Use ORIG_NODE attribute on DoctrineAnnotationDec…
Browse files Browse the repository at this point in the history
…orator on handle @\ after generic (#5285)

* [BetterPhpDocParser] Use ORIG_NODE attribute on DoctrineAnnotationDecorator on handle @\ after generic

* cs fix
  • Loading branch information
samsonasik authored Nov 25, 2023
1 parent 5adf574 commit 3f42ee9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 1 addition & 6 deletions packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -342,11 +341,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 3f42ee9

Please sign in to comment.