diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php b/lib/Doctrine/ODM/MongoDB/DocumentManager.php index 34aea720c5..71429c0c0a 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php @@ -564,6 +564,11 @@ public function unlock(object $document): void * @param string $documentName The name of the Document. * * @return ObjectRepository The repository. + * + * @template T of object + * @psalm-param class-string $documentName + * + * @psalm-return ObjectRepository */ public function getRepository($documentName) { @@ -657,6 +662,11 @@ public function getPartialReference(string $documentName, $identifier): object * @param mixed $id * @param int $lockMode * @param int $lockVersion + * + * @template T of object + * @psalm-param class-string $className + * + * @psalm-return T|null */ public function find($className, $id, $lockMode = LockMode::NONE, $lockVersion = null): ?object { diff --git a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php index 1d5ce672e3..ca0cbe3154 100644 --- a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php +++ b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php @@ -66,6 +66,8 @@ * The DocumentPersister is responsible for persisting documents. * * @internal + * + * @template T of object */ final class DocumentPersister { @@ -466,6 +468,10 @@ public function refresh(object $document): void * * @todo Check identity map? loadById method? Try to guess whether * $criteria is the id? + * + * @psalm-param T|null $document + * + * @psalm-return T|null */ public function load($criteria, ?object $document = null, array $hints = [], int $lockMode = 0, ?array $sort = null): ?object { @@ -620,6 +626,10 @@ public function unlock(object $document): void * @param array $hints Hints for document creation. * * @return object The filled and managed document object. + * + * @psalm-param T|null $document + * + * @psalm-return T */ private function createDocument(array $result, ?object $document = null, array $hints = []): object { diff --git a/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php b/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php index 4bf62aa923..39c02b82ae 100644 --- a/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php +++ b/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php @@ -30,10 +30,17 @@ * * This class is designed for inheritance and users can subclass this class to * write their own repositories with business-specific methods to locate documents. + * + * @template T of object + * @template-implements Selectable + * @template-implements ObjectRepository */ class DocumentRepository implements ObjectRepository, Selectable { - /** @var string */ + /** + * @var string + * @psalm-var class-string + */ protected $documentName; /** @var DocumentManager */ @@ -227,6 +234,9 @@ public function matching(Criteria $criteria): ArrayCollection return new ArrayCollection($iterator->toArray()); } + /** + * @psalm-return DocumentPersister + */ protected function getDocumentPersister(): DocumentPersister { return $this->uow->getDocumentPersister($this->documentName); diff --git a/lib/Doctrine/ODM/MongoDB/Repository/GridFSRepository.php b/lib/Doctrine/ODM/MongoDB/Repository/GridFSRepository.php index d5c03347d6..e166640c77 100644 --- a/lib/Doctrine/ODM/MongoDB/Repository/GridFSRepository.php +++ b/lib/Doctrine/ODM/MongoDB/Repository/GridFSRepository.php @@ -6,6 +6,10 @@ use Doctrine\Persistence\ObjectRepository; +/** + * @template T of object + * @template-extends ObjectRepository + */ interface GridFSRepository extends ObjectRepository { /** diff --git a/lib/Doctrine/ODM/MongoDB/Repository/RepositoryFactory.php b/lib/Doctrine/ODM/MongoDB/Repository/RepositoryFactory.php index 17ed6ce6ce..36ba029d91 100644 --- a/lib/Doctrine/ODM/MongoDB/Repository/RepositoryFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Repository/RepositoryFactory.php @@ -14,6 +14,10 @@ interface RepositoryFactory { /** * Gets the repository for a document class. + * + * @template T of object + * @psalm-param class-string $documentName + * @psalm-return ObjectRepository */ public function getRepository(DocumentManager $documentManager, string $documentName): ObjectRepository; } diff --git a/lib/Doctrine/ODM/MongoDB/Repository/ViewRepository.php b/lib/Doctrine/ODM/MongoDB/Repository/ViewRepository.php index 8fe74e0cd5..2022db6030 100644 --- a/lib/Doctrine/ODM/MongoDB/Repository/ViewRepository.php +++ b/lib/Doctrine/ODM/MongoDB/Repository/ViewRepository.php @@ -7,6 +7,10 @@ use Doctrine\ODM\MongoDB\Aggregation\Builder; use Doctrine\Persistence\ObjectRepository; +/** + * @template T of object + * @template-extends ObjectRepository + */ interface ViewRepository extends ObjectRepository { /** diff --git a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php index 1bca49dde4..0e601e6726 100644 --- a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php +++ b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php @@ -324,6 +324,10 @@ public function getParentAssociation(object $document): ?array /** * Get the document persister instance for the given document name + * + * @template T of object + * @psalm-param class-string $documentName + * @psalm-return Persisters\DocumentPersister */ public function getDocumentPersister(string $documentName): Persisters\DocumentPersister { @@ -2611,6 +2615,11 @@ public function getClassNameForAssociation(array $mapping, $data): string /** * Creates a document. Used for reconstitution of documents during hydration. + * + * @template T of object + * @psalm-param class-string $className + * @psalm-param T|null $document + * @psalm-return T */ public function getOrCreateDocument(string $className, array $data, array &$hints = [], ?object $document = null): object { @@ -2633,6 +2642,7 @@ public function getOrCreateDocument(string $className, array $data, array &$hint } if (! empty($hints[Query::HINT_READ_ONLY])) { + /** @psalm-var T $document */ $document = $class->newInstance(); $this->hydratorFactory->hydrate($document, $data, $hints);