|
2 | 2 |
|
3 | 3 | namespace PHPStan\Reflection\Doctrine;
|
4 | 4 |
|
| 5 | +use PHPStan\Broker\Broker; |
| 6 | +use PHPStan\Reflection\BrokerAwareExtension; |
5 | 7 | use PHPStan\Reflection\Dummy\DummyMethodReflection;
|
6 | 8 |
|
7 |
| -class EntityRepositoryClassReflectionExtension implements \PHPStan\Reflection\MethodsClassReflectionExtension |
| 9 | +class EntityRepositoryClassReflectionExtension implements \PHPStan\Reflection\MethodsClassReflectionExtension, BrokerAwareExtension |
8 | 10 | {
|
9 | 11 |
|
| 12 | + /** @var Broker */ |
| 13 | + private $broker; |
| 14 | + |
| 15 | + public function setBroker(Broker $broker): void |
| 16 | + { |
| 17 | + $this->broker = $broker; |
| 18 | + } |
| 19 | + |
10 | 20 | public function hasMethod(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName): bool
|
11 | 21 | {
|
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'); |
20 | 39 | }
|
21 | 40 |
|
22 | 41 | public function getMethod(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName): \PHPStan\Reflection\MethodReflection
|
|
0 commit comments