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
RenameClassRector with callback support #3023
RenameClassRector with callback support #3023
Conversation
2930e41
to
b6c1c4b
Compare
...enaming/Rector/Name/RenameClassRector/FixtureWithCallback/rename_class_with_callback.php.inc
Outdated
Show resolved
Hide resolved
9311624
to
e9e3550
Compare
e9e3550
to
808c226
Compare
808c226
to
9b56cb1
Compare
Hi, please let me know if I need to make any additional changes or if the current implementation is acceptable. Thanks! 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add fixture and with existing configured rule test an verify rename class named __callbacks__
, eg:
'__callbacks__' => 'NewSomeOtherClass'
will be renamed working ok?
it seems class named __callbacks__
is valid https://3v4l.org/TJlNv
f17c6e8
to
4dc1bd5
Compare
Hi, good point. 👍 I have changed the value of |
@@ -33,7 +33,7 @@ final class RenameClassRector extends AbstractRector implements ConfigurableRect | |||
/** | |||
* @var string | |||
*/ | |||
public const CALLBACKS = '__callbacks__'; | |||
public const CALLBACKS = '#callbacks#'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
Thank you 👏 |
Hi @dorrogeray I'm thinking about this rule in retrospect and it seems it's crossing border with PHPStan and IDE fetaures. It doesn't seem useful to public nor standard sets. Instead these should be handled in a custom Rector rule or better required by PHPStan, as probably is already :) I wan to keep IDE features and dynamic code sepeate, as we focus mainly on strict and clear no-brainer refactorings. Morover with upcoming GPT coding that goes the opposite way. Despite that, I want to thank you for your input and work 🙏 |
Hi, sorry for the delayed response. I put this together in order to try to answer question in discussion: Make RenameClassRector more flexible by supporting callbacks?:
Callback enforcing Exception suffix on classes which extend
Exception
:Callback enforcing Interface suffix on classes which are interfaces:
In final solution the
NodeNameResolver
andReflectionProvider
could be injected via DI, but it did not work in the unit test out of the box so I have passed it via argument for simplicity.I don't like the magical callbacks configuration key, but I am not sure what is the best approach here, to keep configuration BC while adding this new feature..