diff --git a/src/Transformer/NullableTransformer.php b/src/Transformer/NullableTransformer.php index 10a8b50..f770be6 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 bf48a57..13450c1 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 9912837..4383ff9 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, ) { } }