From a22686797f12a3ddac362ab850f4b795318ad54f Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sat, 22 May 2021 17:40:20 +0200 Subject: [PATCH] Improve phpdoc return type --- lib/Doctrine/ODM/MongoDB/DocumentManager.php | 6 ++++-- .../ODM/MongoDB/Mapping/ClassMetadataFactory.php | 4 ++++ .../Repository/AbstractRepositoryFactory.php | 14 +++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php b/lib/Doctrine/ODM/MongoDB/DocumentManager.php index de17d0dee8..ec59e4c680 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php @@ -16,7 +16,9 @@ use Doctrine\ODM\MongoDB\Proxy\Resolver\ProxyManagerClassNameResolver; use Doctrine\ODM\MongoDB\Query\FilterCollection; use Doctrine\ODM\MongoDB\Repository\DocumentRepository; +use Doctrine\ODM\MongoDB\Repository\GridFSRepository; use Doctrine\ODM\MongoDB\Repository\RepositoryFactory; +use Doctrine\ODM\MongoDB\Repository\ViewRepository; use Doctrine\Persistence\ObjectManager; use Doctrine\Persistence\ObjectRepository; use InvalidArgumentException; @@ -563,8 +565,8 @@ public function unlock(object $document): void * @param string $documentName The name of the Document. * @psalm-param class-string $documentName * - * @return ObjectRepository The repository. - * @psalm-return ObjectRepository + * @return ObjectRepository|DocumentRepository|GridFSRepository|ViewRepository The repository. + * @psalm-return DocumentRepository|GridFSRepository|ViewRepository * * @template T of object */ diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php index ae0a88fa74..822159f131 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php @@ -35,6 +35,10 @@ * to a document database. * * @internal + * + * @method ClassMetadata[] getAllMetadata() + * @method ClassMetadata[] getLoadedMetadata() + * @method ClassMetadata getMetadataFor($className) */ final class ClassMetadataFactory extends AbstractClassMetadataFactory { diff --git a/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php b/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php index e0b6ee2c4b..89a6c54686 100644 --- a/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php @@ -26,6 +26,13 @@ abstract class AbstractRepositoryFactory implements RepositoryFactory */ private $repositoryList = []; + /** + * @psalm-param class-string $documentName + * + * @psalm-return DocumentRepository|GridFSRepository|ViewRepository + * + * @template T of object + */ public function getRepository(DocumentManager $documentManager, string $documentName): ObjectRepository { $metadata = $documentManager->getClassMetadata($documentName); @@ -45,7 +52,12 @@ public function getRepository(DocumentManager $documentManager, string $document /** * Create a new repository instance for a document class. * - * @return ObjectRepository|GridFSRepository|ViewRepository + * @psalm-param class-string $documentName + * + * @return ObjectRepository|DocumentRepository|GridFSRepository|ViewRepository + * @psalm-return DocumentRepository|GridFSRepository|ViewRepository + * + * @template T of object */ protected function createRepository(DocumentManager $documentManager, string $documentName): ObjectRepository {