Skip to content

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

@CMH-Benny

Description

@CMH-Benny

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions