diff --git a/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php b/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php index 8a076cca5..52c1f3943 100644 --- a/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php @@ -167,8 +167,8 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla $code .= sprintf( <<class->fieldMappings['%2\$s']['nullable']) && array_key_exists('%1\$s', \$data))) { \$value = \$data['%1\$s']; if (\$value !== null) { @@ -224,7 +224,7 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla $code .= sprintf( <<<'EOF' - /** @ReferenceOne */ + // ReferenceOne if (isset($data['%1$s']) || (! empty($this->class->fieldMappings['%2$s']['nullable']) && array_key_exists('%1$s', $data))) { $return = $data['%1$s']; if ($return !== null) { @@ -275,11 +275,11 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla $mappedByMapping = $targetClass->fieldMappings[$mapping['mappedBy']]; $mappedByFieldName = ClassMetadata::getReferenceFieldName($mappedByMapping['storeAs'], $mapping['mappedBy']); $criteria = array_merge( - array($mappedByFieldName => $data['_id']), - isset($this->class->fieldMappings['%2$s']['criteria']) ? $this->class->fieldMappings['%2$s']['criteria'] : array() + [$mappedByFieldName => $data['_id']], + $this->class->fieldMappings['%2$s']['criteria'] ?? [] ); - $sort = isset($this->class->fieldMappings['%2$s']['sort']) ? $this->class->fieldMappings['%2$s']['sort'] : array(); - $return = $this->dm->getUnitOfWork()->getDocumentPersister($className)->load($criteria, null, array(), 0, $sort); + $sort = $this->class->fieldMappings['%2$s']['sort'] ?? []; + $return = $this->dm->getUnitOfWork()->getDocumentPersister($className)->load($criteria, null, [], 0, $sort); $this->class->reflFields['%2$s']->setValue($document, $return); $hydratedData['%2$s'] = $return; @@ -293,8 +293,8 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla $code .= sprintf( <<<'EOF' - /** @Many */ - $mongoData = isset($data['%1$s']) ? $data['%1$s'] : null; + // ReferenceMany & EmbedMany + $mongoData = $data['%1$s'] ?? null; if ($mongoData !== null && ! is_array($mongoData)) { throw HydratorException::associationTypeMismatch('%3$s', '%1$s', 'array', gettype($mongoData)); @@ -320,7 +320,7 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla $code .= sprintf( <<<'EOF' - /** @EmbedOne */ + // EmbedOne if (isset($data['%1$s']) || (! empty($this->class->fieldMappings['%2$s']['nullable']) && array_key_exists('%1$s', $data))) { $return = $data['%1$s']; if ($return !== null) { @@ -370,23 +370,20 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla use Doctrine\ODM\MongoDB\Query\Query; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; +use function array_key_exists; +use function gettype; +use function is_array; + /** * THIS CLASS WAS GENERATED BY THE DOCTRINE ODM. DO NOT EDIT THIS FILE. */ class $hydratorClassName implements HydratorInterface { - private \$dm; - private \$class; - - public function __construct(DocumentManager \$dm, ClassMetadata \$class) - { - \$this->dm = \$dm; - \$this->class = \$class; - } + public function __construct(private DocumentManager \$dm, private ClassMetadata \$class) {} - public function hydrate(object \$document, array \$data, array \$hints = array()): array + public function hydrate(object \$document, array \$data, array \$hints = []): array { - \$hydratedData = array(); + \$hydratedData = []; %s return \$hydratedData; } }