GetRepositoryServiceLocatorToRepositoryServiceInjectionRector

Turns $this->entityManager->getRepository(...) on entity that supports service repository, to constructor injection

-use Doctrine\ORM\Mapping as ORM;
-
-/**
- * @ORM\Entity(repositoryClass="SomeRepository")
- */
-class SomeEntity
+final class SomeClass
 {
-}
+    public function __construct(
+        private ServiceDocumentRepository $someEntityRepository
+    ) {
+    }

-use Doctrine\Bundle\MongoDBBundle\Repository\ServiceDocumentRepository;
-
-final class SomeRepository extends ServiceDocumentRepository
-{
-}
-
-final class SomeClass
-{
     public function run()
     {
-        return $this->getRepository(SomeEntity::class)->find(1);
+        return $this->someEntityRepository->find(1);
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\Doctrine\CodeQuality\Rector\Class_\GetRepositoryServiceLocatorToRepositoryServiceInjectionRector;

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