2
2
3
3
namespace PHPStan \Stubs \Doctrine ;
4
4
5
+ use PHPStan \BetterReflection \Reflector \Exception \IdentifierNotFound ;
6
+ use PHPStan \BetterReflection \Reflector \Reflector ;
5
7
use PHPStan \PhpDoc \StubFilesExtension ;
6
- use function class_exists ;
7
8
use function dirname ;
8
- use function trait_exists ;
9
9
10
10
class StubFilesExtensionLoader implements StubFilesExtension
11
11
{
12
12
13
+ /** @var Reflector */
14
+ private $ reflector ;
15
+
13
16
/** @var bool */
14
17
private $ bleedingEdge ;
15
18
16
19
public function __construct (
20
+ Reflector $ reflector ,
17
21
bool $ bleedingEdge
18
22
)
19
23
{
24
+ $ this ->reflector = $ reflector ;
20
25
$ this ->bleedingEdge = $ bleedingEdge ;
21
26
}
22
27
@@ -34,10 +39,20 @@ public function getFiles(): array
34
39
$ path . '/EntityRepository.stub ' ,
35
40
];
36
41
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 ) {
41
56
$ files [] = $ stubsDir . '/LazyServiceEntityRepository.stub ' ;
42
57
} else {
43
58
$ files [] = $ stubsDir . '/ServiceEntityRepository.stub ' ;
0 commit comments