-
-
Notifications
You must be signed in to change notification settings - Fork 739
Recognise Doctrine's EntityManagerInterface in ControllerMethodInjectionToConstructorRector #9692
Copy link
Copy link
Closed
rectorphp/rector-symfony
#926Labels
Description
Feature Request
When running the ControllerMethodInjectionToConstructorRector rule, it would be handy (for my team's use case, at least) if Rector treated Doctrine\ORM\EntityManagerInterface as an injected dependency that can be moved to the constructor.
Currently, Rector will skip/ignore EntityManagerInterface - see https://getrector.com/demo/35aee427-2c85-40d0-9d12-fc64c86d7f82.
I'm guessing this is because (for us) the parameter gets injected based on it being bound in the services configuration -i.e.:
services:
_defaults:
autoconfigure: true
autowire: true
bind:
$em: "@doctrine.orm.Main_entity_manager"
$emFoo: "@doctrine.orm.Foo_entity_manager"
# [...]Desired Behaviour
<?php
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ExampleController extends AbstractController
{
+ public function __construct(private readonly EntityManagerInterface $em)
+ {
+ }
+
- public function example(EntityManagerInterface $em): void
+ public function example(): void
{
- dump($em);
+ dump($this->em);
}
}
If this wouldn't be considered generally useful in an "always-on" form, perhaps ControllerMethodInjectionToConstructorRector could take a list of class names to treat the same as (non-bound) services?
Thanks!
Reactions are currently unavailable