Skip to content

Commit

Permalink
fix(extract): fix extract with @param in constructor doc block (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx authored Jun 19, 2024
2 parents 1a74e80 + 1d67d2b commit 4ca1546
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Extractor/GetTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions tests/AutoMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
17 changes: 17 additions & 0 deletions tests/Fixtures/IssueParamDocBlock/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace AutoMapper\Tests\Fixtures\IssueParamDocBlock;

final readonly class Foo
{
/**
* @param string[] $foo
*/
public function __construct(
public string $bar,
public array $foo,
) {
}
}

0 comments on commit 4ca1546

Please sign in to comment.