From af8fbfa2d6ce648565128b20f4f49df41d2804d7 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:29:56 +0700 Subject: [PATCH] perf(`ObjectToObjectTransformer`): Prevent delegating to `MainTransformer` if the current value in a dynamic property is a scalar. --- CHANGELOG.md | 2 ++ src/Transformer/Implementation/ObjectToObjectTransformer.php | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 303a52b1..6937fd82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ * fix: mapping to object extending `stdClass` to property with no setter. * feat: `stdClass` to `stdClass` mapping should work correctly. * feat: Mapping to existing values in a dynamic property. +* perf(`ObjectToObjectTransformer`): Prevent delegating to `MainTransformer` if + the current value in a dynamic property is a scalar. ## 1.0.0 diff --git a/src/Transformer/Implementation/ObjectToObjectTransformer.php b/src/Transformer/Implementation/ObjectToObjectTransformer.php index ff9aaf6b..8bd70c57 100644 --- a/src/Transformer/Implementation/ObjectToObjectTransformer.php +++ b/src/Transformer/Implementation/ObjectToObjectTransformer.php @@ -587,7 +587,10 @@ private function mapDynamicProperties( } - if ($currentTargetPropertyValue === null) { + if ( + $currentTargetPropertyValue === null + || is_scalar($currentTargetPropertyValue) + ) { /** @psalm-suppress MixedAssignment */ $targetPropertyValue = $sourcePropertyValue; } else {