From 36827e4f4882a2dc4792bea5c8e2b8283b42dfd6 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Tue, 20 Sep 2022 01:26:41 +0200 Subject: [PATCH] Fix Psalm errors --- lib/Doctrine/ODM/MongoDB/DocumentManager.php | 5 ++++- lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | 2 +- lib/Doctrine/ODM/MongoDB/UnitOfWork.php | 1 + .../MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php b/lib/Doctrine/ODM/MongoDB/DocumentManager.php index 9b323c430b..81363ee435 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php @@ -621,13 +621,15 @@ public function getReference(string $documentName, $identifier): object /** @psalm-var ClassMetadata $class */ $class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\')); assert($class instanceof ClassMetadata); + /** @psalm-var T|false $document */ $document = $this->unitOfWork->tryGetById($identifier, $class); // Check identity map first, if its already in there just return it. - if ($document) { + if ($document !== false) { return $document; } + /** @psalm-var T&GhostObjectInterface $document */ $document = $this->proxyFactory->getProxy($class, $identifier); $this->unitOfWork->registerManaged($document, $identifier, []); @@ -689,6 +691,7 @@ public function find($className, $id, $lockMode = LockMode::NONE, $lockVersion = { $repository = $this->getRepository($className); if ($repository instanceof DocumentRepository) { + /** @psalm-var DocumentRepository $repository */ return $repository->find($id, $lockMode, $lockVersion); } diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php index f7c9606f7e..cc214dc926 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php @@ -2247,7 +2247,7 @@ public function mapField(array $mapping): array break; default: if (! empty($this->generatorOptions['type'])) { - $mapping['type'] = $this->generatorOptions['type']; + $mapping['type'] = (string) $this->generatorOptions['type']; } elseif (empty($mapping['type'])) { $mapping['type'] = $this->generatorType === self::GENERATOR_TYPE_INCREMENT ? Type::INT : Type::CUSTOMID; } diff --git a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php index 106176e9e3..84510496a1 100644 --- a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php +++ b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php @@ -367,6 +367,7 @@ public function getDocumentPersister(string $documentName): Persisters\DocumentP $this->persisters[$documentName] = new Persisters\DocumentPersister($pb, $this->dm, $this, $this->hydratorFactory, $class); } + /** @psalm-var Persisters\DocumentPersister */ return $this->persisters[$documentName]; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php index a7bccc8c6b..63a8e57ab8 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php @@ -268,6 +268,7 @@ private function getRepository(string $className = File::class): GridFSRepositor assert($repository instanceof GridFSRepository); + /** @psalm-var GridFSRepository */ return $repository; }