Repository: symfony/symfony
File: src/Symfony/Component/ObjectMapper/ObjectMapper.php (PHP)

Code before:

        $shouldRecurse = $mapping?->recursive ?? $this->recursive;
        if (\is_callable($shouldRecurse) || \is_string($shouldRecurse)) {
            if ($fn = $this->getCallable($shouldRecurse, $this->conditionCallableLocator)) {
                $shouldRecurse = $this->call($fn, $value, $source, $target);
            }
        }

        if (false === $shouldRecurse) {
            return $value;
        }

        if (
            \is_object($value)
            && ($innerMetadata = $this->metadataFactory->create($value))
            && ($mapTo = $this->getMapTarget($innerMetadata, $value, $source, $target))
            && (\is_string($mapTo->target) && class_exists($mapTo->target))
        ) {
            if ($this->lazy && !\is_object($mapping?->transform)) {
                $targetClass = $mapTo->target;
                $refl = new \ReflectionClass($targetClass);
                $sourceValue = $value;
                $mapper = $this->objectMapper ?? $this;

                return $refl->newLazyGhost(function ($lazyObject) use ($mapper, $sourceValue) {
                    $mapper->map($sourceValue, $lazyObject);
                });
            }

            // Eager recursion
            $value = $this->applyTransforms($mapTo, $value, $source, $target);

            if ($value === $source) {
                $value = $target;
            } elseif ($objectMap->offsetExists($value)) {
                $value = $objectMap[$value];
            } else {
                $value = ($this->objectMapper ?? $this)->map($value, $mapTo->target);
            }
        }

        return $value;
    }

    /**
     * Store the value either the constructor arguments or as a property to be mapped.
     *
     * @param array<string, mixed> $mapToProperties
     * @param array<string, mixed> $ctorArguments
     */
    private function storeValue(string $propertyName, array &$mapToProperties, array &$ctorArguments, mixed $value): void

Review comment (suggestion):
```suggestion
                return $r->newLazyGhost(static function ($lazyObject) use ($mapper, $value) {
                    $mapper->map($value, $lazyObject);
```

Code after:
            $value = $this->applyTransforms($mapping, $value, $source, $target);
        }

        if (
            \is_object($value)
            && ($innerMetadata = $this->metadataFactory->create($value))
            && ($mapTo = $this->getMapTarget($innerMetadata, $value, $source, $target))
            && (\is_string($mapTo->target) && class_exists($mapTo->target))
        ) {
            $value = $this->applyTransforms($mapTo, $value, $source, $target);

            if ($value === $source) {
                $value = $target;
            } elseif ($objectMap->offsetExists($value)) {
                $value = $objectMap[$value];
            } elseif (\PHP_VERSION_ID < 80400) {
                return ($this->objectMapper ?? $this)->map($value, $mapTo->target);
            } else {
                $refl = new \ReflectionClass($mapTo->target);
                $mapper = $this->objectMapper ?? $this;

                return $refl->newLazyGhost(function ($target) use ($mapper, $value, $objectMap) {
                    $previousMap = $this->objectMap;
                    $this->objectMap = $objectMap;
                    try {
                        $objectMap[$value] = $mapper->map($value, $target);
                    } finally {
                        $this->objectMap = $previousMap;
                    }
                });
            }
        }

        return $value;
    }

    /**
     * Store the value either the constructor arguments or as a property to be mapped.
     *
     * @param array<string, mixed> $mapToProperties
     * @param array<string, mixed> $ctorArguments
     */
    private function storeValue(string $propertyName, array &$mapToProperties, array &$ctorArguments, mixed $value): void
    {
        if (\array_key_exists($propertyName, $ctorArguments)) {
            $ctorArguments[$propertyName] = $value;

            return;
        }

        $mapToProperties[$propertyName] = $value;