phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

`getManagerForClass` is not correctly resolved by Phpstan-doctrine

Open VincentLanglet opened this issue 2 years ago • 1 comments

The following code

class Foo
{
    private EntityManagerInterface $entityManager;

    public function __construct(
        ManagerRegistry $managerRegistry,
    ) {
        $this->entityManager = $managerRegistry->getManagerForClass(Bar::class);
    }

return the errors

Property Foo::$entityManager (Doctrine\ORM\EntityManagerInterface) does not accept Doctrine\Persistence\ObjectManager|null.  

Since EntityManager::getRepository give the correct Repository class

Since 1.2.0, this extension resolve entity metadata without objectManagerLoader. I was wondering if the same could be done for managerRegistry.

VincentLanglet avatar Mar 23 '22 20:03 VincentLanglet

Do you think this can be done by this extension @ondrejmirtes ? Any recommendation how-to ? I can try

VincentLanglet avatar Mar 29 '22 13:03 VincentLanglet