diff --git a/rules-tests/CodeQuality/Rector/Class_/EventListenerToEventSubscriberRector/Fixture/skip_when_as_announce_listener_attribute_exists_on_methods.php.inc b/rules-tests/CodeQuality/Rector/Class_/EventListenerToEventSubscriberRector/Fixture/skip_when_as_announce_listener_attribute_exists_on_methods.php.inc new file mode 100644 index 000000000..ba86b0513 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/EventListenerToEventSubscriberRector/Fixture/skip_when_as_announce_listener_attribute_exists_on_methods.php.inc @@ -0,0 +1,13 @@ +phpAttributeAnalyzer->hasPhpAttribute($class, SymfonyAttribute::AS_EVENT_LISTENER)) { - return true; + foreach (self::LISTENER_ATTRIBUTES as $attribute) { + if ($this->phpAttributeAnalyzer->hasPhpAttribute($class, $attribute)) { + return true; + } } foreach ($class->getMethods() as $classMethod) { @@ -180,8 +198,10 @@ private function hasAsListenerAttribute(Class_ $class): bool continue; } - if ($this->phpAttributeAnalyzer->hasPhpAttribute($classMethod, SymfonyAttribute::AS_EVENT_LISTENER)) { - return true; + foreach (self::LISTENER_ATTRIBUTES as $attribute) { + if ($this->phpAttributeAnalyzer->hasPhpAttribute($classMethod, $attribute)) { + return true; + } } } diff --git a/src/Enum/SymfonyAttribute.php b/src/Enum/SymfonyAttribute.php index 6ee0b0d40..7c434c566 100644 --- a/src/Enum/SymfonyAttribute.php +++ b/src/Enum/SymfonyAttribute.php @@ -16,6 +16,21 @@ final class SymfonyAttribute public const string AS_EVENT_LISTENER = 'Symfony\Component\EventDispatcher\Attribute\AsEventListener'; + // Workflow listener attributes (Symfony 7.1+) + public const string AS_ANNOUNCE_LISTENER = 'Symfony\Component\Workflow\Attribute\AsAnnounceListener'; + + public const string AS_COMPLETED_LISTENER = 'Symfony\Component\Workflow\Attribute\AsCompletedListener'; + + public const string AS_ENTER_LISTENER = 'Symfony\Component\Workflow\Attribute\AsEnterListener'; + + public const string AS_ENTERED_LISTENER = 'Symfony\Component\Workflow\Attribute\AsEnteredListener'; + + public const string AS_GUARD_LISTENER = 'Symfony\Component\Workflow\Attribute\AsGuardListener'; + + public const string AS_LEAVE_LISTENER = 'Symfony\Component\Workflow\Attribute\AsLeaveListener'; + + public const string AS_TRANSITION_LISTENER = 'Symfony\Component\Workflow\Attribute\AsTransitionListener'; + public const string ROUTE = 'Symfony\Component\Routing\Attribute\Route'; public const string IS_GRANTED = 'Symfony\Component\Security\Http\Attribute\IsGranted';