From 165b3d81878e539c69b1a270ce04d7b9089b9279 Mon Sep 17 00:00:00 2001 From: Ilya Orlov Date: Fri, 13 Sep 2024 19:00:25 +0500 Subject: [PATCH] fix: regression after #184 --- src/Transformer/NullableTransformer.php | 6 +++--- src/Transformer/NullableTransformerFactory.php | 4 ---- tests/Fixtures/ConstructorWithDefaultValues.php | 1 + 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Transformer/NullableTransformer.php b/src/Transformer/NullableTransformer.php index 10a8b508..f770be69 100644 --- a/src/Transformer/NullableTransformer.php +++ b/src/Transformer/NullableTransformer.php @@ -11,7 +11,7 @@ use PhpParser\Node\Stmt; /** - * Tansformer decorator to handle null values. + * Transformer decorator to handle null values. * * @author Joel Wurtz * @@ -51,9 +51,9 @@ public function transform(Expr $input, Expr $target, PropertyMetadata $propertyM $itemStatements[] = new Stmt\Expression(new $assignClass($newOutput, $output)); } - if ($input instanceof Expr\ArrayDimFetch) { + if ($propertyMapping->source->checkExists) { /* - * if `$input` is an array access, let's validate if the array key exists and is not null: + * if `$input` is an array access or stdClass, let's validate if the key exists and is not null: * * if (isset($value['key'])) { */ diff --git a/src/Transformer/NullableTransformerFactory.php b/src/Transformer/NullableTransformerFactory.php index bf48a575..13450c1c 100644 --- a/src/Transformer/NullableTransformerFactory.php +++ b/src/Transformer/NullableTransformerFactory.php @@ -21,10 +21,6 @@ final class NullableTransformerFactory implements TransformerFactoryInterface, P public function getTransformer(TypesMatching $types, SourcePropertyMetadata $source, TargetPropertyMetadata $target, MapperMetadata $mapperMetadata): ?TransformerInterface { - if (null !== $target->parameterInConstructor) { - return null; - } - $sourceType = $types->getSourceUniqueType(); if (null === $sourceType) { diff --git a/tests/Fixtures/ConstructorWithDefaultValues.php b/tests/Fixtures/ConstructorWithDefaultValues.php index 99128377..4383ff9d 100644 --- a/tests/Fixtures/ConstructorWithDefaultValues.php +++ b/tests/Fixtures/ConstructorWithDefaultValues.php @@ -11,6 +11,7 @@ public function __construct( public ?int $foo = 1, public int $bar = 0, public array $someOtters = [], + public ?IntDTO $nullableObject = null, ) { } }