EventListenerToEventSubscriberRector

Change Symfony Event listener class to Event Subscriber based on configuration in service.yaml file

-class SomeListener
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+class SomeEventSubscriber implements EventSubscriberInterface
 {
+     /**
+      * @return string[]
+      */
+     public static function getSubscribedEvents(): array
+     {
+         return ['some_event' => 'methodToBeCalled'];
+     }
+
      public function methodToBeCalled()
      {
      }
-}
-
-// in config.yaml
-services:
-    SomeListener:
-        tags:
-            - { name: kernel.event_listener, event: 'some_event', method: 'methodToBeCalled' }
+}

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\Symfony\CodeQuality\Rector\Class_\EventListenerToEventSubscriberRector;

return RectorConfig::configure()
    ->withRules([
        EventListenerToEventSubscriberRector::class,
    ]);
SETS:  Code Quality