Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Comment on lines -21 to +24
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is essential to ensure when orig node exists, no need to re-fill with node, use whatever ORIG_NODE value is, eg: null for reprint.


return $clonedNode;
}
}