diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 16a8eab8..edf69316 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 2 + level: 3 paths: - src - tests diff --git a/src/Command/DoctrineCommand.php b/src/Command/DoctrineCommand.php index 0e7c25d1..a04f88ad 100644 --- a/src/Command/DoctrineCommand.php +++ b/src/Command/DoctrineCommand.php @@ -9,6 +9,8 @@ use InvalidArgumentException; use Symfony\Component\Console\Command\Command; +use function assert; + /** * Base class for Doctrine console commands to extend from. * @@ -59,6 +61,8 @@ protected function getEntityManager($name, $shardId = null) throw new InvalidArgumentException('Shards are not supported anymore using doctrine/dbal >= 3'); } + assert($manager instanceof EntityManager); + return $manager; } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 06cf3dbd..0de8099a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -277,6 +277,8 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition ->prototype('array'); $this->configureDbalDriverNode($replicaNode); + assert($node instanceof ArrayNodeDefinition); + return $node; } @@ -822,6 +824,8 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition ->end() ->end(); + assert($node instanceof ArrayNodeDefinition); + return $node; } @@ -850,6 +854,8 @@ private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition $node->addDefaultsIfNotSet(); } + assert($node instanceof ArrayNodeDefinition); + return $node; } diff --git a/src/Registry.php b/src/Registry.php index c24da664..f3275d5c 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -6,8 +6,8 @@ use Doctrine\ORM\ORMException; use Doctrine\Persistence\Proxy; use ProxyManager\Proxy\LazyLoadingInterface; -use Psr\Container\ContainerInterface; use Symfony\Bridge\Doctrine\ManagerRegistry; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\VarExporter\LazyObjectInterface; use Symfony\Contracts\Service\ResetInterface; @@ -23,7 +23,7 @@ class Registry extends ManagerRegistry implements ResetInterface * @param string[] $connections * @param string[] $entityManagers */ - public function __construct(ContainerInterface $container, array $connections, array $entityManagers, string $defaultConnection, string $defaultEntityManager) + public function __construct(Container $container, array $connections, array $entityManagers, string $defaultConnection, string $defaultEntityManager) { $this->container = $container; diff --git a/src/Repository/ServiceEntityRepositoryProxy.php b/src/Repository/ServiceEntityRepositoryProxy.php index 07dd6c0a..9755faca 100644 --- a/src/Repository/ServiceEntityRepositoryProxy.php +++ b/src/Repository/ServiceEntityRepositoryProxy.php @@ -27,6 +27,7 @@ */ class ServiceEntityRepositoryProxy extends EntityRepository implements ServiceEntityRepositoryInterface { + /** @var EntityRepository */ private ?EntityRepository $repository = null; /** @param class-string $entityClass The class name of the entity this repository manages */ @@ -111,11 +112,13 @@ protected function getClassMetadata(): ClassMetadata return ($this->repository ??= $this->resolveRepository())->getClassMetadata(); } + /** @phpstan-return AbstractLazyCollection&Selectable */ public function matching(Criteria $criteria): AbstractLazyCollection&Selectable { return ($this->repository ??= $this->resolveRepository())->matching($criteria); } + /** @return EntityRepository */ private function resolveRepository(): EntityRepository { $manager = $this->registry->getManagerForClass($this->entityClass); @@ -127,6 +130,9 @@ private function resolveRepository(): EntityRepository )); } - return new EntityRepository($manager, $manager->getClassMetadata($this->entityClass)); + /** @var ClassMetadata $classMetadata */ + $classMetadata = $manager->getClassMetadata($this->entityClass); + + return new EntityRepository($manager, $classMetadata); } } diff --git a/tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Repository/TestCustomClassRepoRepository.php b/tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Repository/TestCustomClassRepoRepository.php index 9a67e056..0c33a76e 100644 --- a/tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Repository/TestCustomClassRepoRepository.php +++ b/tests/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Repository/TestCustomClassRepoRepository.php @@ -2,7 +2,7 @@ namespace Fixtures\Bundles\RepositoryServiceBundle\Repository; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; /** @@ -11,7 +11,7 @@ */ class TestCustomClassRepoRepository extends EntityRepository { - public function getEntityManager(): EntityManager + public function getEntityManager(): EntityManagerInterface { return parent::getEntityManager(); }