Search code examples
phpsymfonydoctrinephpstormsymfony-3.4

How to make PhpStorm understand the type of a Doctrine repository


I use Symfony 3.4 with Doctrine and this is how I get one of my repositories:

$members = $this->getDoctrine()->getRepository(Member::class)->getAllMembersForClient($client);

Developing with PhpStorm, the IDE does not know what the method getRepository(Member:class) returns and therefore doesn't offer auto-complete. So it shows me an error for the method call getAllMembersForClient($client)

Is there a good way to fix this? How do other Doctrine users handle this problem?


Solution

  • Double-check that you've installed the 'Symfony' plugin, as that generally provides the functionality to recognise that getRepository(Member::class) would return the repository that is defined by annotations (or other means) to PHPStorm.

    You should be able to find it in the menu: Settings> Plugins> {search for 'symfony'}. If it is not already in the list, 'Browse Repositories...' under the list of plugins.

    You have to enable it per project (File> Settings> Languages & Framework> PHP> Symfony) & also install the Php Annotation plugin.