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;
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\Symfony\Symfony42\Rector\MethodCall\ContainerGetToConstructorInjectionRector;
return RectorConfig::configure()
->withRules([
ContainerGetToConstructorInjectionRector::class,
]);