[Php80] Keep trailing doc comment after annotation in AnnotationToAttributeRector#8160
Merged
Merged
Conversation
…ributeRector A doctrine annotation swallows the doc comment placed on the line(s) below it into its original content, so removing the converted tag also removed the comment. Split the trailing comment back out into a PhpDocTextNode instead. Fixes rectorphp/rector#9786
Member
Author
|
LGTM 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9786
When
AnnotationToAttributeRectorconverts a Symfony/Doctrine annotation to an attribute, a doc comment placed on the line(s) below the annotation was deleted along with it.The doctrine annotation swallows that trailing comment into its original content, so removing the converted tag removed the comment too. A comment placed above the annotation was already kept (it is a separate text node) — only the comment after was lost.
Fix: split the trailing comment back out into its own docblock text node instead of dropping it.
Before
/** * @Route("/path", name="action") - * this comment must be kept */ - public function action() + #[Route(path: '/path', name: 'action')] + public function action()After
Works for multi-line annotations too, and does not misread parentheses inside string values (
"/path/(foo)") or leftover annotation syntax (a stray)) as a comment.