EventSubscriberInterfaceToAttributeRector

Replace EventSubscriberInterface with AsDoctrineListener attribute(s)

+use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
 use Doctrine\ORM\Event\PrePersistEventArgs;
 use Doctrine\ORM\Event\PostUpdateEventArgs;
-use Doctrine\Common\EventSubscriberInterface;
 use Doctrine\ORM\Events;

-class MyEventSubscriber implements EventSubscriberInterface
+#[AsDoctrineListener(event: Events::postUpdate)]
+#[AsDoctrineListener(event: Events::prePersist)]
+class MyEventSubscriber
 {
-    public function getSubscribedEvents()
-    {
-        return array(
-            Events::postUpdate,
-            Events::prePersist,
-        );
-    }
-
     public function postUpdate(PostUpdateEventArgs $args)
     {
         // ...
     }

     public function prePersist(PrePersistEventArgs $args)
     {
         // ...
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\Doctrine\Bundle210\Rector\Class_\EventSubscriberInterfaceToAttributeRector;

return RectorConfig::configure()
    ->withRules([
        EventSubscriberInterfaceToAttributeRector::class,
    ]);