-
-
Notifications
You must be signed in to change notification settings - Fork 739
EventListenerToEventSubscriberRector should skip classes with Symfony 7.1 Workflow attributes #9685
Description
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:
AsAnnounceListenerAsCompletedListenerAsEnterListenerAsEnteredListenerAsGuardListenerAsLeaveListenerAsTransitionListener
(full FQCNs under Symfony\Component\Workflow\Attribute\)
How to reproduce
- Have a class with e.g.
#[AsTransitionListener]on methods, noEventSubscriberInterface - Run rector
- Rector adds
implements EventSubscriberInterface+ generatesgetSubscribedEvents()- 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.