diff --git a/CHANGELOG.md b/CHANGELOG.md index f7014cc7..1cee8ed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * test: Mapping test first version. * refactor: rename `RefuseToHandleException` to `RefuseToTransformException`. * perf(`CopyTransformer`): Move identity check to the beginning. +* fix(`MainTransformer`): Fix possible bug involving an existing target. ## 0.5.10 diff --git a/src/MainTransformer/MainTransformer.php b/src/MainTransformer/MainTransformer.php index de7cc6d0..e0734ebd 100644 --- a/src/MainTransformer/MainTransformer.php +++ b/src/MainTransformer/MainTransformer.php @@ -76,13 +76,16 @@ public function transform( Context $context, string $path = null, ): mixed { - // if targettype is not provided, guess it from target - // if the target is also missing then the target is mixed + // if target is provided, guess the type from it. + // if target is not provided, use the provided target type. if it is + // also not provided, then the target type is mixed. - if (count($targetTypes) === 0) { - if ($target === null) { + if ($target === null) { + if (count($targetTypes) === 0) { $targetTypes = [MixedType::instance()]; - } else { + } + } else { + if (count($targetTypes) === 0) { $targetTypes = [$this->typeResolver->guessTypeFromVariable($target)]; } }