diff --git a/rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/skip_event_subscriber_method.php.inc b/rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/skip_event_subscriber_method.php.inc new file mode 100644 index 00000000..2c607feb --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/skip_event_subscriber_method.php.inc @@ -0,0 +1,28 @@ +getRequest()->attributes->get('_controller'); + } + + /** + * @return array + */ + public static function getSubscribedEvents(): array + { + return [ + KernelEvents::REQUEST => 'onRequest', + ]; + } +} diff --git a/rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/skip_session_interface.php.inc b/rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/skip_session_interface.php.inc new file mode 100644 index 00000000..6db13968 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/skip_session_interface.php.inc @@ -0,0 +1,18 @@ +invalidate(); + } +} diff --git a/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php b/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php index b19b091f..e8e826a6 100644 --- a/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php +++ b/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php @@ -183,6 +183,10 @@ public function refactor(Node $node): ?Node new ObjectType(SymfonyClass::USER_INTERFACE), new ObjectType('DateTimeInterface'), new ObjectType(SymfonyClass::UUID), + // event listener method, not a controller action + new ObjectType(SymfonyClass::EVENT), + // request-scoped, must stay in the action method + new ObjectType(SymfonyClass::SESSION_INTERFACRE), ] )) { continue; diff --git a/src/Enum/SymfonyClass.php b/src/Enum/SymfonyClass.php index b1c5d9df..b9ec898c 100644 --- a/src/Enum/SymfonyClass.php +++ b/src/Enum/SymfonyClass.php @@ -20,6 +20,8 @@ final class SymfonyClass public const string EVENT_DISPATCHER_INTERFACE = 'Symfony\Contracts\EventDispatcher\EventDispatcherInterface'; + public const string EVENT = 'Symfony\Contracts\EventDispatcher\Event'; + public const string VALIDATOR_INTERFACE = 'Symfony\Component\Validator\Validator\ValidatorInterface'; public const string LOGGER_INTERFACE = 'Psr\Log\LoggerInterface';