22
33namespace PHPStan \Stubs \Doctrine ;
44
5+ use PHPStan \BetterReflection \Reflector \Exception \IdentifierNotFound ;
6+ use PHPStan \BetterReflection \Reflector \Reflector ;
57use PHPStan \PhpDoc \StubFilesExtension ;
6- use function class_exists ;
78use function dirname ;
8- use function trait_exists ;
99
1010class StubFilesExtensionLoader implements StubFilesExtension
1111{
1212
13+ /** @var Reflector */
14+ private $ reflector ;
15+
1316 /** @var bool */
1417 private $ bleedingEdge ;
1518
1619 public function __construct (
20+ Reflector $ reflector ,
1721 bool $ bleedingEdge
1822 )
1923 {
24+ $ this ->reflector = $ reflector ;
2025 $ this ->bleedingEdge = $ bleedingEdge ;
2126 }
2227
@@ -34,10 +39,20 @@ public function getFiles(): array
3439 $ path . '/EntityRepository.stub ' ,
3540 ];
3641
37- if (
38- trait_exists ('Symfony\Component\VarExporter\LazyGhostTrait ' )
39- && class_exists ('Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository ' )
40- ) {
42+ $ hasLazyServiceEntityRepositoryAsParent = false ;
43+
44+ try {
45+ $ serviceEntityRepository = $ this ->reflector ->reflectClass ('Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository ' );
46+ if ($ serviceEntityRepository ->getParentClass () !== null ) {
47+ /** @var class-string $lazyServiceEntityRepositoryName */
48+ $ lazyServiceEntityRepositoryName = 'Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository ' ;
49+ $ hasLazyServiceEntityRepositoryAsParent = $ serviceEntityRepository ->getParentClass ()->getName () === $ lazyServiceEntityRepositoryName ;
50+ }
51+ } catch (IdentifierNotFound $ e ) {
52+ // pass
53+ }
54+
55+ if ($ hasLazyServiceEntityRepositoryAsParent ) {
4156 $ files [] = $ stubsDir . '/LazyServiceEntityRepository.stub ' ;
4257 } else {
4358 $ files [] = $ stubsDir . '/ServiceEntityRepository.stub ' ;
0 commit comments