From 1d67d2b126c4b5fc486f2f52d13dc74b844640cc Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Wed, 19 Jun 2024 16:33:45 +0200 Subject: [PATCH] fix(extract): fix extract with @param in constructor doc block --- CHANGELOG.md | 3 +++ src/Extractor/GetTypeTrait.php | 2 +- tests/AutoMapperTest.php | 13 +++++++++++++ tests/Fixtures/IssueParamDocBlock/Foo.php | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/Fixtures/IssueParamDocBlock/Foo.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c7ac5e8..34ba100a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- [GH#164](https://github.com/jolicode/automapper/pull/164) Fix type extract with @param in constructor doc block + ## [9.1.0] - 2024-06-06 ### Added - [GH#153](https://github.com/jolicode/automapper/pull/153) Handle DateTime format in MapTo/MapFrom/Mapper attributes diff --git a/src/Extractor/GetTypeTrait.php b/src/Extractor/GetTypeTrait.php index 9d8d346c..65a3cd25 100644 --- a/src/Extractor/GetTypeTrait.php +++ b/src/Extractor/GetTypeTrait.php @@ -62,7 +62,7 @@ private function extractFromDocBlock(string|false|null $rawDocNode, string $clas if ( $tagDocNode->value instanceof ParamTagValueNode - && $tagName !== '@param' + && $tagName === '@param' && $tagDocNode->value->parameterName !== '$' . $property ) { continue; diff --git a/tests/AutoMapperTest.php b/tests/AutoMapperTest.php index ef98f940..33418c16 100644 --- a/tests/AutoMapperTest.php +++ b/tests/AutoMapperTest.php @@ -1550,4 +1550,17 @@ public function testItCanMapToClassesWithPrivatePropertiesInConstructor(): void ) ); } + + public function testParamDocBlock(): void + { + $this->buildAutoMapper(); + + $foo = new Fixtures\IssueParamDocBlock\Foo('bar', ['foo1', 'foo2']); + $array = $this->autoMapper->map($foo, 'array'); + + self::assertSame([ + 'bar' => 'bar', + 'foo' => ['foo1', 'foo2'], + ], $array); + } } diff --git a/tests/Fixtures/IssueParamDocBlock/Foo.php b/tests/Fixtures/IssueParamDocBlock/Foo.php new file mode 100644 index 00000000..8061f184 --- /dev/null +++ b/tests/Fixtures/IssueParamDocBlock/Foo.php @@ -0,0 +1,17 @@ +