diff --git a/extension.neon b/extension.neon index 7c436bae..e7bdba93 100644 --- a/extension.neon +++ b/extension.neon @@ -24,7 +24,6 @@ parameters: - stubs/EntityManager.stub - stubs/EntityManagerDecorator.stub - stubs/EntityManagerInterface.stub - - stubs/ServiceEntityRepository.stub - stubs/MongoClassMetadataInfo.stub - stubs/Persistence/ManagerRegistry.stub diff --git a/src/Stubs/Doctrine/StubFilesExtensionLoader.php b/src/Stubs/Doctrine/StubFilesExtensionLoader.php index 9e912865..c33d8a4a 100644 --- a/src/Stubs/Doctrine/StubFilesExtensionLoader.php +++ b/src/Stubs/Doctrine/StubFilesExtensionLoader.php @@ -3,6 +3,7 @@ namespace PHPStan\Stubs\Doctrine; use PHPStan\PhpDoc\StubFilesExtension; +use function class_exists; use function dirname; class StubFilesExtensionLoader implements StubFilesExtension @@ -20,16 +21,25 @@ public function __construct( public function getFiles(): array { - $path = dirname(dirname(dirname(__DIR__))) . '/stubs'; + $stubsDir = dirname(dirname(dirname(__DIR__))) . '/stubs'; + $path = $stubsDir; if ($this->bleedingEdge === true) { $path .= '/bleedingEdge'; } - return [ + $files = [ $path . '/ORM/QueryBuilder.stub', $path . '/EntityRepository.stub', ]; + + if (class_exists('Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository')) { + $files[] = $stubsDir . '/LazyServiceEntityRepository.stub'; + } else { + $files[] = $stubsDir . '/ServiceEntityRepository.stub'; + } + + return $files; } } diff --git a/stubs/LazyServiceEntityRepository.stub b/stubs/LazyServiceEntityRepository.stub new file mode 100644 index 00000000..225fc1d5 --- /dev/null +++ b/stubs/LazyServiceEntityRepository.stub @@ -0,0 +1,18 @@ + + */ +class ServiceEntityRepository extends LazyServiceEntityRepository { +} + +/** + * @template TEntityClass of object + * @template-extends EntityRepository + */ +class LazyServiceEntityRepository extends EntityRepository { +}