GetBySymfonyStringToConstructorInjectionRector

Converts typical Symfony services like $this->get("validator") in commands/controllers to constructor injection (step 3/x)

 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Component\Validator\Validator\ValidatorInterface;

 final class SomeController extends Controller
 {
+    public function __construct(private ValidatorInterface $validator)
+
     public function someMethod()
     {
-        $someType = $this->get('validator');
+        $someType = $this->validator;
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\Symfony\DependencyInjection\Rector\Class_\GetBySymfonyStringToConstructorInjectionRector;

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