PR rectorphp/rector-symfony#616 added a check so EventListenerToEventSubscriberRector skips classes that use #[AsEventListener]. Great fix, but it only covers that one attribute.
Symfony 7.1 added a bunch of workflow-specific listener attributes that do essentially the same thing: register listeners without needing EventSubscriberInterface. The rule doesn't know about any of them, so it happily adds
back the interface and getSubscribedEvents() to classes that don't need it.
The attributes that are missing from the check
All from symfony/workflow, added in 7.1:
AsAnnounceListener
AsCompletedListener
AsEnterListener
AsEnteredListener
AsGuardListener
AsLeaveListener
AsTransitionListener
(full FQCNs under Symfony\Component\Workflow\Attribute\)
How to reproduce
- Have a class with e.g.
#[AsTransitionListener] on methods, no EventSubscriberInterface
- Run rector
- Rector adds
implements EventSubscriberInterface + generates getSubscribedEvents() - undoing what the attributes are for
What should happen
Rector should just leave it alone, same as it already does for #[AsEventListener].
Fix idea
Extend hasAsListenerAttribute() in EventListenerToEventSubscriberRector to check for all 7 workflow attributes, not just AsEventListener. Probably add the constants to SymfonyAttribute enum too.
Happy to submit a PR for this if that helps.
Side note
There's also a separate bug where the rule produces a double suffix like TransactionWorkflowEventSubscriberEventSubscriber during rename, but that's a different issue, just mentioning it here for context.
Refs
PR rectorphp/rector-symfony#616 added a check so
EventListenerToEventSubscriberRectorskips classes that use#[AsEventListener]. Great fix, but it only covers that one attribute.Symfony 7.1 added a bunch of workflow-specific listener attributes that do essentially the same thing: register listeners without needing
EventSubscriberInterface. The rule doesn't know about any of them, so it happily addsback the interface and
getSubscribedEvents()to classes that don't need it.The attributes that are missing from the check
All from
symfony/workflow, added in 7.1:AsAnnounceListenerAsCompletedListenerAsEnterListenerAsEnteredListenerAsGuardListenerAsLeaveListenerAsTransitionListener(full FQCNs under
Symfony\Component\Workflow\Attribute\)How to reproduce
#[AsTransitionListener]on methods, noEventSubscriberInterfaceimplements EventSubscriberInterface+ generatesgetSubscribedEvents()- undoing what the attributes are forWhat should happen
Rector should just leave it alone, same as it already does for
#[AsEventListener].Fix idea
Extend
hasAsListenerAttribute()inEventListenerToEventSubscriberRectorto check for all 7 workflow attributes, not justAsEventListener. Probably add the constants toSymfonyAttributeenum too.Happy to submit a PR for this if that helps.
Side note
There's also a separate bug where the rule produces a double suffix like
TransactionWorkflowEventSubscriberEventSubscriberduring rename, but that's a different issue, just mentioning it here for context.Refs