psalm / psalm-plugin-doctrine

Stubs to let Psalm understand Doctrine better
86 stars 43 forks source link

UndefinedInterfaceMethod-errors for methods in repository #16

Open cklm opened 5 years ago

cklm commented 5 years ago

Hi, thanks for the great plugin!

I have a question - I'm getting UndefinedInterfaceMethod-errors in my symfony4-project like this:

ERROR: UndefinedInterfaceMethod - src\ControllerShop\IndexController.php:45:68 - Method Doctrine\Common\Persistence\ObjectRepository::createquerybuilder does not exist
$qb = $this->getDoctrine()->getRepository(Article::class)->createQueryBuilder('a');

ERROR: UndefinedInterfaceMethod - src\ControllerShop\IndexController.php:98:83 - Method Doctrine\Common\Persistence\ObjectRepository::findforcompany does not exist
$staffToken = $this->getDoctrine()->getRepository(StaffToken::class)->findForCompany($company, $token);

Problem seems to be, that the methods are not checked against the real repository, but the generic ObjectRepository. Is it right, that the plugin does not recognise these methods in the repositories? Am I doing something wrong here? Thanks in advance!

weirdan commented 5 years ago

What does $this->getDoctrine() return?

cklm commented 5 years ago

What does $this->getDoctrine() return?

an instance of Doctrine\Common\Persistence\ManagerRegistry

weirdan commented 5 years ago

Ok, the reason you're seeing it now is that getRepository() is declared to return ObjectRepository. DPP (this plugin) would have to figure out there's specific repository for this entity class (thus it depends on #10)