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
 {
-     public function methodToBeCalled()
+     /**
+      * @return string[]
+      */
+     public static function getSubscribedEvents(): array
      {
+         return ['some_event' => 'methodToBeCalled'];
      }
-}

-// in config.yaml
-services:
-    SomeListener:
-        tags:
-            - { name: kernel.event_listener, event: 'some_event', method: 'methodToBeCalled' }
+     public function 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