Find the best Rector rule to solve your problem


GetToConstructorInjectionRector

Turns fetching of dependencies via $this->get() to constructor injection in Command and Controller

 use Symfony\Bundle\FrameworkBundle\Controller\Controller;

 final class SomeController extend Controller
 {
+    public function __construct(SomeService $someService)
+    {
+        $this->someService = $someService;
+    }
+
     public function someMethod()
     {
-        // ...
-        $this->get('some_service');
+        $this->someService;
     }
 }

ContainerGetToConstructorInjectionRector

Turns fetching of dependencies via $container->get() in ContainerAware to constructor injection in Command and Controller in Symfony

 final class SomeCommand extends ContainerAwareCommand
 {
+    public function __construct(SomeService $someService)
+    {
+        $this->someService = $someService;
+    }
+
     public function someMethod()
     {
         // ...
-        $this->getContainer()->get('some_service');
-        $this->container->get('some_service');
+        $this->someService;
+        $this->someService;
     }
 }

ContainerGetNameToTypeInTestsRector

Change $container->get("some_name") to bare type, useful since Symfony 3.4

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     public function run()
     {
         $container = $this->getContainer();
-        $someClass = $container->get('some_name');
+        $someClass = $container->get(SomeType::class);
     }
 }