Skip to content

Commit

Permalink
Fix Psalm errors caused by ORM 2.12 and Persistence 2.5 (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Apr 22, 2022
1 parent 4f4387c commit d592dd3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 9 additions & 1 deletion Repository/ContainerRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
final class ContainerRepositoryFactory implements RepositoryFactory
{
/** @var ObjectRepository[] */
/** @var array<string, ObjectRepository> */
private $managedRepositories = [];

/** @var ContainerInterface */
Expand Down Expand Up @@ -68,6 +68,13 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName
return $this->getOrCreateRepository($entityManager, $metadata);
}

/**
* @param ClassMetadata<TEntity> $metadata
*
* @return ObjectRepository<TEntity>
*
* @template TEntity of object
*/
private function getOrCreateRepository(
EntityManagerInterface $entityManager,
ClassMetadata $metadata
Expand All @@ -79,6 +86,7 @@ private function getOrCreateRepository(

$repositoryClassName = $metadata->customRepositoryClassName ?: $entityManager->getConfiguration()->getDefaultRepositoryClassName();

/** @psalm-var ObjectRepository<TEntity> */
return $this->managedRepositories[$repositoryHash] = new $repositoryClassName($entityManager, $metadata);
}
}
2 changes: 1 addition & 1 deletion Repository/ServiceEntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* }
* }
*
* @template T
* @template T of object
* @template-extends EntityRepository<T>
*/
class ServiceEntityRepository extends EntityRepository implements ServiceEntityRepositoryInterface
Expand Down
12 changes: 6 additions & 6 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
<file name="Registry.php"/>
</projectFiles>
<issueHandlers>
<TooManyTemplateParams>
<errorLevel type="suppress">
<!-- This happens on PHP 7.1 because there is no 7.1 compatible doctrine/orm version having template annotations -->
<file name="Repository/ServiceEntityRepository.php"/>
</errorLevel>
</TooManyTemplateParams>
<InvalidArrayOffset>
<errorLevel type="suppress">
<!-- requires a release of https://github.com/doctrine/dbal/pull/5261 -->
<file name="Tests/ConnectionFactoryTest.php"/>
</errorLevel>
</InvalidArrayOffset>
<UndefinedClass>
<errorLevel type="suppress">
<!-- We use the "Foo" namespace in unit tests. We are aware that those classes don't exist. -->
<referencedClass name="Foo\*"/>
</errorLevel>
</UndefinedClass>
<UndefinedDocblockClass>
<errorLevel type="suppress">
<!-- https://github.com/symfony/symfony/issues/45609 -->
Expand Down

0 comments on commit d592dd3

Please sign in to comment.