Skip to content

Commit 4ca1546

Browse files
authored
fix(extract): fix extract with @param in constructor doc block (#164)
2 parents 1a74e80 + 1d67d2b commit 4ca1546

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- [GH#164](https://github.com/jolicode/automapper/pull/164) Fix type extract with @param in constructor doc block
12+
1013
## [9.1.0] - 2024-06-06
1114
### Added
1215
- [GH#153](https://github.com/jolicode/automapper/pull/153) Handle DateTime format in MapTo/MapFrom/Mapper attributes

src/Extractor/GetTypeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function extractFromDocBlock(string|false|null $rawDocNode, string $clas
6262

6363
if (
6464
$tagDocNode->value instanceof ParamTagValueNode
65-
&& $tagName !== '@param'
65+
&& $tagName === '@param'
6666
&& $tagDocNode->value->parameterName !== '$' . $property
6767
) {
6868
continue;

tests/AutoMapperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,4 +1550,17 @@ public function testItCanMapToClassesWithPrivatePropertiesInConstructor(): void
15501550
)
15511551
);
15521552
}
1553+
1554+
public function testParamDocBlock(): void
1555+
{
1556+
$this->buildAutoMapper();
1557+
1558+
$foo = new Fixtures\IssueParamDocBlock\Foo('bar', ['foo1', 'foo2']);
1559+
$array = $this->autoMapper->map($foo, 'array');
1560+
1561+
self::assertSame([
1562+
'bar' => 'bar',
1563+
'foo' => ['foo1', 'foo2'],
1564+
], $array);
1565+
}
15531566
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AutoMapper\Tests\Fixtures\IssueParamDocBlock;
6+
7+
final readonly class Foo
8+
{
9+
/**
10+
* @param string[] $foo
11+
*/
12+
public function __construct(
13+
public string $bar,
14+
public array $foo,
15+
) {
16+
}
17+
}

0 commit comments

Comments
 (0)