Skip to content
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

EventListenerToEventSubscriberRector - Do I have to skip it, when #[AsEventListener] Attribute is used? #8532

Open
CMH-Benny opened this issue Mar 8, 2024 · 2 comments

Comments

@CMH-Benny
Copy link

CMH-Benny commented Mar 8, 2024

Question

Hey, I am updating a symfony project with rector and I so much love it! Thanks for this amazing tool :)
I am almost done, only SYMFONY_CODE_QUALITY is missing.

Rector always trys to convert EventListeners to EventSubscribers even if I use the Attribute and I wondered why.
I found this blog about it: https://tomasvotruba.com/blog/2019/07/22/how-to-convert-listeners-to-subscribers-and-reduce-your-configs/

But in Symfony 6.4 upwards we also have the #[AsEventListener] Attribute, which not only makes the "no config" argument obsolete, but also allows to target methods, so you can add multiple Listeners to the same method for different events, or have multiple handler methods in one class etc.

There is really no reason anymore to change to EventSubscriber then, or am I wrong?
Wouldn't it be better and more modern to have a EventSubscriberToAsEventListenerAttributeRector and a EventListenerToAsEventListenerAttributeRector instead? Or at least make it aware of that attribute and don't run that rector in that case?

Thanks in advance for your answers <3

@samsonasik
Copy link
Member

Could you create failing fixture PR at https://github.com/rectorphp/rector-symfony/tree/5ce789ddc9f145d4d93496db165ef9daa9be4424/rules-tests/CodeQuality/Rector/Class_/EventListenerToEventSubscriberRector/Fixture , eg: you can name it: skip_when_as_event_listener_attribute_exists.php.inc there

thank you.

@CMH-Benny
Copy link
Author

Hey, I hope this is correct: rectorphp/rector-symfony#589

Wasn't sure if that will work, since IDE is complaining about same class names in the same file, but apparently we don't want Rector to change them in those cases, correct? :)

Thanks in Advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants