Skip to content

Commit 98a7072

Browse files
committed
Fixed error if Doctrine\ORM\EntityRepository class is not defined
1 parent b7f2f1d commit 98a7072

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/Reflection/Doctrine/EntityRepositoryClassReflectionExtension.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,40 @@
22

33
namespace PHPStan\Reflection\Doctrine;
44

5+
use PHPStan\Broker\Broker;
6+
use PHPStan\Reflection\BrokerAwareExtension;
57
use PHPStan\Reflection\Dummy\DummyMethodReflection;
68

7-
class EntityRepositoryClassReflectionExtension implements \PHPStan\Reflection\MethodsClassReflectionExtension
9+
class EntityRepositoryClassReflectionExtension implements \PHPStan\Reflection\MethodsClassReflectionExtension, BrokerAwareExtension
810
{
911

12+
/** @var Broker */
13+
private $broker;
14+
15+
public function setBroker(Broker $broker): void
16+
{
17+
$this->broker = $broker;
18+
}
19+
1020
public function hasMethod(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName): bool
1121
{
12-
return (
13-
$classReflection->getName() === 'Doctrine\ORM\EntityRepository'
14-
|| $classReflection->isSubclassOf('Doctrine\ORM\EntityRepository')
15-
) && (
16-
strpos($methodName, 'findBy') === 0
17-
|| strpos($methodName, 'findOneBy') === 0
18-
|| strpos($methodName, 'countBy') === 0
19-
);
22+
if (
23+
strpos($methodName, 'findBy') !== 0
24+
&& strpos($methodName, 'findOneBy') !== 0
25+
&& strpos($methodName, 'countBy') !== 0
26+
) {
27+
return false;
28+
}
29+
30+
if ($classReflection->getName() === 'Doctrine\ORM\EntityRepository') {
31+
return true;
32+
}
33+
34+
if (!$this->broker->hasClass('Doctrine\ORM\EntityRepository')) {
35+
return false;
36+
}
37+
38+
return $classReflection->isSubclassOf('Doctrine\ORM\EntityRepository');
2039
}
2140

2241
public function getMethod(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName): \PHPStan\Reflection\MethodReflection

0 commit comments

Comments
 (0)