EventListenerToEventSubscriberRector - Do I have to skip it, when #[AsEventListener] Attribute is used?
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
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.
Hey, I hope this is correct: https://github.com/rectorphp/rector-symfony/pull/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
I'm looking into this...
Fixed in https://github.com/rectorphp/rector-symfony/pull/616 :+1:
Thank you so much <3