feat: add ConvertStaticToSelfRector#7161
Conversation
rules/CodeQuality/Rector/Class_/StaticToSelfStaticPropertyFetchOnFinalClassRector.php
Outdated
Show resolved
Hide resolved
98d0a5b to
85e9ac7
Compare
|
Hey, what's the difference to previous you've worked on? |
|
There's a big difference---there's several concerns going on here. I would have probably put most of these into a single rule, but the other classes were already created and I didn't want to make breaking changes, however, I can refactor existing rules if you like:
|
|
I see. So we have similar rule for class names, constants and method calls, but not for properties, right? In that case ✔️ |
|
Is there any reason to have 3 different rules for these or would you recommend using 1 to ease the maintenance? |
|
If it was me I would put all of these into the same rule especially since the target the same node Class_ and have basically the same structure |
|
@TomasVotruba |
|
@samsonasik I meant property, method call and class constants. |
|
@TomasVotruba, all of those rules (beside the class constants) only handle final classes, however, non-final classes with private methods/properties can also be updated |
|
@calebdw I see. Would you recommend to use 1 rule? It's pretty confusing to me to have 3 rules that do 95 % the same checks. |
|
Yes, I would recommend 1 rule, that will both make it easier to maintain and easier for users to discover. Would you like me to do that? Is it okay to remove/rename a rule on a minor version? |
|
Imo, separare rules as for now is better, shared service that allow change based on type target is fine, but keep separate rules, the reason is user will allow step by step apply change that easier to review and merge. |
|
Personally, I think it's better to just review all the |
|
The goal of levelling is to allow gradual step, and I prefer shared service, different rules, that easy to make upgrade code quality, easy to propose PR and merge, improve next level, If there is a bug, change the shared service only. But of course, I will let @TomasVotruba decide. |
@calebdw Yes, that would make more sense. That's why I was confused by this PR in the first place. Should be one rule to think about this logic :) Go for it. Keep old rule class for BC and mark it with |
85e9ac7 to
981bbda
Compare
|
@TomasVotruba, @samsonasik this has been refactored into a single rule 👍 |
| } | ||
|
|
||
| return null; | ||
| return $this->convertStaticToSelfRector->refactor($node); |
There was a problem hiding this comment.
I prefer to not call rector rule (as service) in other rector rule.
Instead, use shared service so it correctly detected as "already called" as rule apply duplication no need verification.
This way, refresh scope and rule apply duplication become blurry and once we have bug in the future because of it, it will hard to verify.
There was a problem hiding this comment.
I think we'll deprecate this rule soon enough with warning error instead.
Should be used as part of set anyway, so no need to add temporary complexity we'd revert.
There was a problem hiding this comment.
The new rule already registered at set
just ensuring user that manually register old rules not got invalid apply rule duplication check because call rector rule as a service.
There was a problem hiding this comment.
deprecate message is better imo, call rector from another rector seems dangerous since it is a visitor itself
There was a problem hiding this comment.
There was a problem hiding this comment.
|
Thank you, let's ship this 👌 |
|
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. |

Hello!
Summary
ConvertStaticToSelfRectorstatic::*→self::*Thanks!