diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php b/lib/Doctrine/ODM/MongoDB/DocumentManager.php index b98f0dc3e..30ce78d24 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php @@ -21,6 +21,7 @@ use Doctrine\ODM\MongoDB\Repository\ViewRepository; use Doctrine\Persistence\Mapping\ProxyClassNameResolver; use Doctrine\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectRepository; use InvalidArgumentException; use Jean85\PrettyVersions; use MongoDB\Client; @@ -218,12 +219,8 @@ public function getClient(): Client return $this->client; } - /** - * Gets the metadata factory used to gather the metadata of classes. - * - * @return ClassMetadataFactoryInterface - */ - public function getMetadataFactory() + /** Gets the metadata factory used to gather the metadata of classes. */ + public function getMetadataFactory(): ClassmetadataFactoryInterface { return $this->metadataFactory; } @@ -235,7 +232,7 @@ public function getMetadataFactory() * * @param object $obj */ - public function initializeObject($obj) + public function initializeObject($obj): void { $this->unitOfWork->initializeObject($obj); } @@ -243,8 +240,12 @@ public function initializeObject($obj) /** * Helper method to check whether a lazy loading proxy or persistent collection has been initialized. */ - public function isUninitializedObject(object $obj): bool + public function isUninitializedObject(mixed $obj): bool { + if (! is_object($obj)) { + return false; + } + return $this->unitOfWork->isUninitializedObject($obj); } @@ -440,7 +441,7 @@ public function createAggregationBuilder(string $documentName): Aggregation\Buil * * @throws InvalidArgumentException When the given $object param is not an object. */ - public function persist($object) + public function persist($object): void { if (! is_object($object)) { throw new InvalidArgumentException(gettype($object)); @@ -460,7 +461,7 @@ public function persist($object) * * @throws InvalidArgumentException When the $object param is not an object. */ - public function remove($object) + public function remove($object): void { if (! is_object($object)) { throw new InvalidArgumentException(gettype($object)); @@ -478,7 +479,7 @@ public function remove($object) * * @throws InvalidArgumentException When the given $object param is not an object. */ - public function refresh($object) + public function refresh($object): void { if (! is_object($object)) { throw new InvalidArgumentException(gettype($object)); @@ -499,7 +500,7 @@ public function refresh($object) * * @throws InvalidArgumentException When the $object param is not an object. */ - public function detach($object) + public function detach($object): void { if (! is_object($object)) { throw new InvalidArgumentException(gettype($object)); @@ -561,7 +562,7 @@ public function unlock(object $document): void * * @template T of object */ - public function getRepository($className) + public function getRepository($className): ObjectRepository { return $this->repositoryFactory->getRepository($this, $className); } @@ -576,7 +577,7 @@ public function getRepository($className) * * @throws MongoDBException */ - public function flush(array $options = []) + public function flush(array $options = []): void { $this->errorIfClosed(); $this->unitOfWork->commit($options); @@ -686,7 +687,7 @@ public function find($className, $id, $lockMode = LockMode::NONE, $lockVersion = * * @param string|null $objectName if given, only documents of this type will get detached */ - public function clear($objectName = null) + public function clear($objectName = null): void { if ($objectName !== null) { trigger_deprecation( @@ -722,7 +723,7 @@ public function close() * * @throws InvalidArgumentException When the $object param is not an object. */ - public function contains($object) + public function contains($object): bool { if (! is_object($object)) { throw new InvalidArgumentException(gettype($object)); diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php index 2a4a35f5d..874bb092e 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php @@ -2216,7 +2216,7 @@ public function isAssociationInverseSide($assocName): bool } /** @param string $assocName */ - public function getAssociationMappedByTargetField($assocName) + public function getAssociationMappedByTargetField($assocName): string { throw new BadMethodCallException(__METHOD__ . '() is not implemented yet.'); } diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php index 4c11dda38..1b78b1e62 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php @@ -40,9 +40,6 @@ */ final class ClassMetadataFactory extends AbstractClassMetadataFactory implements ClassMetadataFactoryInterface { - /** @var string */ - protected $cacheSalt = '$MONGODBODMCLASSMETADATA'; - /** @var DocumentManager The DocumentManager instance */ private DocumentManager $dm; @@ -55,6 +52,11 @@ final class ClassMetadataFactory extends AbstractClassMetadataFactory implements /** @var EventManager The event manager instance */ private EventManager $evm; + public function __construct() + { + $this->cacheSalt = '$MONGODBODMCLASSMETADATA'; + } + public function setDocumentManager(DocumentManager $dm): void { $this->dm = $dm; @@ -82,7 +84,7 @@ protected function initialize(): void } /** @param string $className */ - protected function onNotFoundMetadata($className) + protected function onNotFoundMetadata($className): ?ClassMetadata { if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) { return null; diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php index f0099c28e..05e4974c4 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php @@ -62,7 +62,7 @@ public function __construct($paths = null, ?Reader $reader = null) $this->addPaths((array) $paths); } - public function isTransient($className) + public function isTransient($className): bool { $classAttributes = $this->getClassAttributes(new ReflectionClass($className)); diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php index 6c288a2d9..b0c2e36bd 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php @@ -79,7 +79,7 @@ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENS parent::__construct($locator, $fileExtension); } - public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\ClassMetadata $metadata) + public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\ClassMetadata $metadata): void { assert($metadata instanceof ClassMetadata); $xmlRoot = $this->getElement($className); diff --git a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php index 71f5f925f..35e49b099 100644 --- a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php +++ b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php @@ -2974,7 +2974,7 @@ public function clearDocumentChangeSet(string $oid): void * @param mixed $oldValue The old value of the property. * @param mixed $newValue The new value of the property. */ - public function propertyChanged($sender, $propertyName, $oldValue, $newValue) + public function propertyChanged($sender, $propertyName, $oldValue, $newValue): void { $oid = spl_object_hash($sender); $class = $this->dm->getClassMetadata($sender::class); diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 366e569ae..bcc870f1f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -25,9 +25,12 @@ - - - + + metadataFactory]]> + + + + diff --git a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php index 81fac9bea..55a9257f8 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php @@ -654,7 +654,7 @@ public function setTransient($value): void $this->transient = $value; } - public function addPropertyChangedListener(PropertyChangedListener $listener) + public function addPropertyChangedListener(PropertyChangedListener $listener): void { $this->_listeners[] = $listener; }