Skip to content

Commit

Permalink
Support DoctrineBundle 2.8.1+
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 7, 2023
1 parent acb0d35 commit e1437a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 0 additions & 1 deletion extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ parameters:
- stubs/EntityManager.stub
- stubs/EntityManagerDecorator.stub
- stubs/EntityManagerInterface.stub
- stubs/ServiceEntityRepository.stub
- stubs/MongoClassMetadataInfo.stub

- stubs/Persistence/ManagerRegistry.stub
Expand Down
14 changes: 12 additions & 2 deletions src/Stubs/Doctrine/StubFilesExtensionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPStan\Stubs\Doctrine;

use PHPStan\PhpDoc\StubFilesExtension;
use function class_exists;
use function dirname;

class StubFilesExtensionLoader implements StubFilesExtension
Expand All @@ -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;
}

}
18 changes: 18 additions & 0 deletions stubs/LazyServiceEntityRepository.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace Doctrine\Bundle\DoctrineBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
* @template TEntityClass of object
* @template-extends LazyServiceEntityRepository<TEntityClass>
*/
class ServiceEntityRepository extends LazyServiceEntityRepository {
}

/**
* @template TEntityClass of object
* @template-extends EntityRepository<TEntityClass>
*/
class LazyServiceEntityRepository extends EntityRepository {
}

0 comments on commit e1437a2

Please sign in to comment.