Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(extract): fix extract with @param in constructor doc block #164

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
) {
}
}
Loading