Skip to content

[Removing] Add RemoveAttributeRector#7142

Closed
mttsch wants to merge 3 commits intorectorphp:mainfrom
mttsch:feature/RemoveAttributeRector
Closed

[Removing] Add RemoveAttributeRector#7142
mttsch wants to merge 3 commits intorectorphp:mainfrom
mttsch:feature/RemoveAttributeRector

Conversation

@mttsch
Copy link
Contributor

@mttsch mttsch commented Aug 11, 2025

No description provided.

@mttsch mttsch marked this pull request as ready for review August 11, 2025 19:11
@mttsch
Copy link
Contributor Author

mttsch commented Aug 11, 2025

This rector rule is inspired by this deprecation of an attribute on methods only.

@mttsch mttsch force-pushed the feature/RemoveAttributeRector branch from 9cd53c4 to 0ea96d0 Compare August 11, 2025 19:13
@mttsch mttsch force-pushed the feature/RemoveAttributeRector branch from 0ea96d0 to 2a86654 Compare August 11, 2025 19:13
@mttsch mttsch force-pushed the feature/RemoveAttributeRector branch from 38ff884 to efa3610 Compare August 12, 2025 03:56
@TomasVotruba
Copy link
Member

@mttsch Could you avoid these force pushes? I'm having problems with reviews of these PRs.

*/
public function refactor(Node $node): ?Node
{
$nodeTypes = [$node::class];
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a hack and prone to be overlapped, the node should covered on visited per definition on getNodeTypes() already, better to add a failing fixture first before this, so we can see possible solution without like this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@samsonasik The use case here is if you an attribute that supports parameters and properties but will not support parameters anymore in the future (deprecation), thus it must be removed from a promoted property. The issue is that attributes on promoted properties act as attributes on the property and the constructor parameter.

Copy link
Member

Choose a reason for hiding this comment

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

That should be handled on ClassMethod level, check its AttrGroups and params, in that case, set position of ClassMethod before Param on getNodeTypes(), then you can remove directly under ClassMethod, or use ClassLike instance have __construct method, and remove the child data.

You can revert this hack logic, then sort getNodeTypes() per possible visited node. If, and if needed to clear child, do from the top to down of node, eg: ClassLike -> getProperty/getMethod __construct, remove target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, but I cannot follow your comment to understand what you mean. Can you may-be re-phrase it?

Copy link
Member

Choose a reason for hiding this comment

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

You can remove the tweak, then we can see the test error to see the better solution.

Nodes are visited from parent to child, if it sorted in order on getNodeTypes() per use case, you can check its child or refactor it child and return the node itself if it has changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@samsonasik I removed the specific code for promoted properties and one code examples fails.

But I still do not understand how the order of node visits is relevant here…

@TomasVotruba
Copy link
Member

I'm looking into this rule and the original use case. What other places we'll use this rule in?
If there is only 1 attribute and ClassMethod, it might be better to create such custom rule for PHPUnit set.

@mttsch
Copy link
Contributor Author

mttsch commented Aug 13, 2025

@TomasVotruba Attributes are relatively new so that I think for now, there has not been such a huge need for this case but it might evolve in the future, thus why create a specific rule and we could also have a generalized rule that can also be used in the future by this project for other cases or by third-party rector users for their specific cases.

@TomasVotruba
Copy link
Member

@mttsch That might be the case, or may not.
I'll go with YAGNI here, untill we have at least 2-3 such cases to re-think. We've had such "generic rules for everything" at first, but it only lead to overcomplicated mess with everything configurable just for one case.

We start with explicit rules and only if repeated often we switch to generic.

I'll close this and re-open if we'll have bigger simple. Thanks for understanding

@mttsch mttsch deleted the feature/RemoveAttributeRector branch August 13, 2025 11:37
@github-actions
Copy link
Contributor

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants