Skip to content

Commit

Permalink
phpstan: lvl 2 -> 3 (#1855)
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky authored Jan 15, 2025
1 parent 92d19dc commit ab136b4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 2
level: 3
paths:
- src
- tests
Expand Down
4 changes: 4 additions & 0 deletions src/Command/DoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;

use function assert;

/**
* Base class for Doctrine console commands to extend from.
*
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
->prototype('array');
$this->configureDbalDriverNode($replicaNode);

assert($node instanceof ArrayNodeDefinition);

return $node;
}

Expand Down Expand Up @@ -822,6 +824,8 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
->end()
->end();

assert($node instanceof ArrayNodeDefinition);

return $node;
}

Expand Down Expand Up @@ -850,6 +854,8 @@ private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition
$node->addDefaultsIfNotSet();
}

assert($node instanceof ArrayNodeDefinition);

return $node;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
8 changes: 7 additions & 1 deletion src/Repository/ServiceEntityRepositoryProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
class ServiceEntityRepositoryProxy extends EntityRepository implements ServiceEntityRepositoryInterface
{
/** @var EntityRepository<T> */
private ?EntityRepository $repository = null;

/** @param class-string<T> $entityClass The class name of the entity this repository manages */
Expand Down Expand Up @@ -111,11 +112,13 @@ protected function getClassMetadata(): ClassMetadata
return ($this->repository ??= $this->resolveRepository())->getClassMetadata();
}

/** @phpstan-return AbstractLazyCollection<int, T>&Selectable<int, T> */
public function matching(Criteria $criteria): AbstractLazyCollection&Selectable
{
return ($this->repository ??= $this->resolveRepository())->matching($criteria);
}

/** @return EntityRepository<T> */
private function resolveRepository(): EntityRepository
{
$manager = $this->registry->getManagerForClass($this->entityClass);
Expand All @@ -127,6 +130,9 @@ private function resolveRepository(): EntityRepository
));
}

return new EntityRepository($manager, $manager->getClassMetadata($this->entityClass));
/** @var ClassMetadata<T> $classMetadata */
$classMetadata = $manager->getClassMetadata($this->entityClass);

return new EntityRepository($manager, $classMetadata);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Fixtures\Bundles\RepositoryServiceBundle\Repository;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;

/**
Expand All @@ -11,7 +11,7 @@
*/
class TestCustomClassRepoRepository extends EntityRepository
{
public function getEntityManager(): EntityManager
public function getEntityManager(): EntityManagerInterface
{
return parent::getEntityManager();
}
Expand Down

0 comments on commit ab136b4

Please sign in to comment.