Skip to content

EventListenerToEventSubscriberRector should skip classes with Symfony 7.1 Workflow attributes #9685

@dionisvl

Description

@dionisvl

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

  1. Have a class with e.g. #[AsTransitionListener] on methods, no EventSubscriberInterface
  2. Run rector
  3. 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

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