-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
[Transform] Do not create a new node if the existing node is already the correct one on AttributeKeyToClassConstFetchRector #5328
Conversation
...ttribute/AttributeKeyToClassConstFetchRector/Fixture/not_replacing_existing_constant.php.inc
Outdated
Show resolved
Hide resolved
rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php
Outdated
Show resolved
Hide resolved
The rule is configurable, you need to register in the config test when needed https://github.com/rectorphp/rector-src/blob/main/rules-tests/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector/config/configured_rule.php |
Please create at least 2 commits, first for failing test case, second for the fix so we know what it tries to fix |
@samsonasik Splitted into two commits as requested. |
...ttribute/AttributeKeyToClassConstFetchRector/Fixture/not_replacing_existing_constant.php.inc
Outdated
Show resolved
Hide resolved
rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php
Outdated
Show resolved
Hide resolved
...-tests/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector/Constants/Constant.php
Outdated
Show resolved
Hide resolved
...ttribute/AttributeKeyToClassConstFetchRector/Fixture/not_replacing_existing_constant.php.inc
Outdated
Show resolved
Hide resolved
rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php
Outdated
Show resolved
Hide resolved
rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php
Outdated
Show resolved
Hide resolved
...ts/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector/Fixture/some_class.php.inc
Outdated
Show resolved
Hide resolved
Please update PR title to something like:
|
Thank you @SerethiX |
As stated in rectorphp/rector#8341 replacing the node, even if it leads to the same reference, forces a change, that is not required.
I added a check to skip recreating the node if the class reference stays the same.
During testing I found out, that resolving the value works differently based on if the referenced class actually exists or not.
So the added testfile currently passes the test, but only because the resolved value is not present as a key in the map.
Is there already a real class with constants that could be used, to make it a real test?