From c6e09a1861e7527046ad5f12faa4b90ac853ac75 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Mon, 15 Jan 2024 06:03:48 +0700 Subject: [PATCH] fix: `NullTransformer` bug. --- CHANGELOG.md | 1 + src/Transformer/NullTransformer.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b42a88c..b1112c03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * feat: Transformers now have the option to have an invariant target type. * fix: Wrong service id for `CopyTransformer`. * fix: Remove cache file & regenerate it if it is corrupt. +* fix: `NullTransformer` bug. ## 0.5.8 diff --git a/src/Transformer/NullTransformer.php b/src/Transformer/NullTransformer.php index 6e314392..77a8d96c 100644 --- a/src/Transformer/NullTransformer.php +++ b/src/Transformer/NullTransformer.php @@ -54,7 +54,11 @@ public function transform( return []; } - throw new InvalidArgumentException(sprintf('Target must be scalar, "%s" given', get_debug_type($targetType)), context: $context); + if (TypeCheck::isNull($targetType)) { + return null; + } + + throw new InvalidArgumentException(sprintf('Target must be scalar, "%s" given.', get_debug_type($targetType)), context: $context); } public function getSupportedTransformation(): iterable