[Php80] Handle RenameClassRector+AnnotationToAttributeRector with auto import and existing attribute defined#5219
Merged
samsonasik merged 7 commits intomainfrom Nov 2, 2023
Merged
Conversation
…o import and existing attribute defined
samsonasik
commented
Nov 2, 2023
Comment on lines
+67
to
+72
| if (! $result instanceof Name && ! $node instanceof FullyQualified) { | ||
| $phpAttributeName = $node->getAttribute(AttributeKey::PHP_ATTRIBUTE_NAME); | ||
| if (is_string($phpAttributeName)) { | ||
| return $this->classRenamer->renameNode(new FullyQualified($phpAttributeName, $node->getAttributes()), $oldToNewClasses, $scope); | ||
| } | ||
| } |
Member
Author
There was a problem hiding this comment.
This is the trick 👍 , on ClassRenamingPostRector, verify that Name is not FullyQualified, which:
$this->phpAttributeGroupFactory->create()can return a Name instead of FullyQualified with bring original attribute name to be renamed, then use it to be returned so it can be processed on next loop on FileProcessor.
Member
Author
|
All checks have passed 🎉 @TomasVotruba I am merging it to have faster feedback to test ;) Sidenote for future improvement: The renamed |
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.
@jambonfarci @stefantalen @TomasVotruba
It seems the issue of:
is when there is already existing attribute defined (there is removed use statement)
when no attribute yet defined, it seems working ok (the use statement is replaced with new one)
it seems when rename a node, we need service to collect the named node need to be collected so it can be used on PostRector to only remove when there is renamed name equal.
Re-work :)
Fixes https://github.com/rectorphp/rector-symfony/issues/535