psalm-plugin-doctrine icon indicating copy to clipboard operation
psalm-plugin-doctrine copied to clipboard

UndefinedInterfaceMethod-errors for methods in repository

Open cklm opened this issue 5 years ago • 3 comments

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!

cklm avatar Jun 07 '19 08:06 cklm

What does $this->getDoctrine() return?

weirdan avatar Jun 07 '19 10:06 weirdan

What does $this->getDoctrine() return?

an instance of Doctrine\Common\Persistence\ManagerRegistry

cklm avatar Jun 07 '19 10:06 cklm

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)

weirdan avatar Jun 07 '19 10:06 weirdan