Skip to content

Commit 6812cf4

Browse files
committed
Fix stubs in regard to LazyServiceEntityRepository again
1 parent ed1a207 commit 6812cf4

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.2 || ^8.0",
10-
"phpstan/phpstan": "^1.9.7"
10+
"phpstan/phpstan": "^1.9.10"
1111
},
1212
"conflict": {
1313
"doctrine/collections": "<1.0",

src/Stubs/Doctrine/StubFilesExtensionLoader.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22

33
namespace PHPStan\Stubs\Doctrine;
44

5+
use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
6+
use PHPStan\BetterReflection\Reflector\Reflector;
57
use PHPStan\PhpDoc\StubFilesExtension;
6-
use function class_exists;
78
use function dirname;
8-
use function trait_exists;
99

1010
class 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

Comments
 (0)