From $container->get(SomeType::class)
in commands to constructor injection (step 2/x)
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
final class SomeCommand extends ContainerAwareCommand
{
+ public function __construct(private SomeType $someType)
+ {
+ }
+
public function someMethod()
{
- $someType = $this->get(SomeType::class);
+ $someType = $this->someType;
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\Symfony\DependencyInjection\Rector\Class_\CommandGetByTypeToConstructorInjectionRector;
return RectorConfig::configure()
->withRules([
CommandGetByTypeToConstructorInjectionRector::class,
]);