diff --git a/CHANGELOG.md b/CHANGELOG.md index 27144d1..be1253b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [GH#184](https://github.com/jolicode/automapper/pull/184) Fix error when mapping from stdClass to constructor with nullable/optional arguments - [GH#185](https://github.com/jolicode/automapper/pull/185) Fix constructor with default parameter array does not work with constructor_arguments context +- [GH#187](https://github.com/jolicode/automapper/pull/187) Fix regression after [GH#184](https://github.com/jolicode/automapper/pull/184) ## [9.1.2] - 2024-09-03 ### Fixed 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, ) { } }