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