diff --git a/CHANGELOG.md b/CHANGELOG.md index f232210c..cc9213b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ * perf(`ObjectToObjectTransformer`): Prevent delegating to `MainTransformer` if the current value in a dynamic property is a scalar. * feat(`PresetMappingFactory`): Add `fromObjectCache()` and `fromObjectCacheReversed()`. +* chore: Simplify remembering mapper. ## 1.0.0 diff --git a/tests/Fixtures/RememberingMapper/RememberingMapper.php b/tests/Fixtures/RememberingMapper/RememberingMapper.php index 41a8ae43..ebd1d79a 100644 --- a/tests/Fixtures/RememberingMapper/RememberingMapper.php +++ b/tests/Fixtures/RememberingMapper/RememberingMapper.php @@ -14,7 +14,6 @@ namespace Rekalogika\Mapper\Tests\Fixtures\RememberingMapper; use Rekalogika\Mapper\Context\Context; -use Rekalogika\Mapper\Exception\UnexpectedValueException; use Rekalogika\Mapper\MapperInterface; use Rekalogika\Mapper\ObjectCache\ObjectCacheFactoryInterface; use Rekalogika\Mapper\Transformer\Context\PresetMapping; @@ -37,29 +36,20 @@ public function reset(): void $this->presetMapping = new PresetMapping(); } + /** @psalm-suppress InvalidReturnType */ public function map(object $source, object|string $target, ?Context $context = null): object { $objectCache = $this->objectCacheFactory->createObjectCache(); - if ($context === null) { - $context = Context::create(); - } - + $context ??= Context::create(); $context = $context->with($objectCache, $this->presetMapping); $result = $this->decorated->map($source, $target, $context); - if (is_object($target)) { - $target = $target::class; - } - - if (!$result instanceof $target) { - throw new UnexpectedValueException(sprintf('Expected instance of "%s", got "%s"', $target, get_class($result))); - } - $newPresetMapping = PresetMappingFactory::fromObjectCacheReversed($objectCache); $this->presetMapping->mergeFrom($newPresetMapping); + /** @psalm-suppress InvalidReturnStatement */ return $result; } }