phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
589 stars 97 forks source link

EntityManager::getRepository should return the correct EntityRepository class #2

Closed teohhanhui closed 6 years ago

teohhanhui commented 7 years ago
$em = $this->managerRegistry->getManager();

$travelDestinationRepository = $em->getRepository(TravelDestination::class);

$childDestinationIdsQueryBuilder = $travelDestinationRepository->getChildrenQueryBuilder($parentDestinationIds);

Line src/AppBundle/ApiPlatform/Doctrine/Orm/Filter/EventLocationFilter.php


99 Call to an undefined method
Doctrine\Common\Persistence\ObjectRepository::getChildrenQueryBuilder()
.


alsciende commented 6 years ago

That would be really great!

ondrejmirtes commented 6 years ago

Some discussion about this is in #8.

ondrejmirtes commented 6 years ago

Copying my comment from the PR discussion:

Besides the point #1 from my comment here, if you're in need of this extension, you shouldn't call $em->getRepository(), but inject the specific EntityRepository (or a child class) in your class directly via dependency injection, as @Ocramius said.

BTW: I'm not a fan of extending EntityRepository at all. It encourages huge god objects with many methods because of 1:1 mapping between repositories and entities. I like much more specific repositories for specific use-cases of an entity. For example one repository for getting translations, another repository for tree manipulation etc.

So I reserve my right to be opinionated and close this PR.

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.