Skip to content

Commit e1437a2

Browse files
committed
Support DoctrineBundle 2.8.1+
1 parent acb0d35 commit e1437a2

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

extension.neon

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ parameters:
2424
- stubs/EntityManager.stub
2525
- stubs/EntityManagerDecorator.stub
2626
- stubs/EntityManagerInterface.stub
27-
- stubs/ServiceEntityRepository.stub
2827
- stubs/MongoClassMetadataInfo.stub
2928

3029
- stubs/Persistence/ManagerRegistry.stub

src/Stubs/Doctrine/StubFilesExtensionLoader.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Stubs\Doctrine;
44

55
use PHPStan\PhpDoc\StubFilesExtension;
6+
use function class_exists;
67
use function dirname;
78

89
class StubFilesExtensionLoader implements StubFilesExtension
@@ -20,16 +21,25 @@ public function __construct(
2021

2122
public function getFiles(): array
2223
{
23-
$path = dirname(dirname(dirname(__DIR__))) . '/stubs';
24+
$stubsDir = dirname(dirname(dirname(__DIR__))) . '/stubs';
25+
$path = $stubsDir;
2426

2527
if ($this->bleedingEdge === true) {
2628
$path .= '/bleedingEdge';
2729
}
2830

29-
return [
31+
$files = [
3032
$path . '/ORM/QueryBuilder.stub',
3133
$path . '/EntityRepository.stub',
3234
];
35+
36+
if (class_exists('Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository')) {
37+
$files[] = $stubsDir . '/LazyServiceEntityRepository.stub';
38+
} else {
39+
$files[] = $stubsDir . '/ServiceEntityRepository.stub';
40+
}
41+
42+
return $files;
3343
}
3444

3545
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace Doctrine\Bundle\DoctrineBundle\Repository;
3+
4+
use Doctrine\ORM\EntityRepository;
5+
6+
/**
7+
* @template TEntityClass of object
8+
* @template-extends LazyServiceEntityRepository<TEntityClass>
9+
*/
10+
class ServiceEntityRepository extends LazyServiceEntityRepository {
11+
}
12+
13+
/**
14+
* @template TEntityClass of object
15+
* @template-extends EntityRepository<TEntityClass>
16+
*/
17+
class LazyServiceEntityRepository extends EntityRepository {
18+
}

0 commit comments

Comments
 (0)