Skip to content

Commit 4620b86

Browse files
committed
PHP annotations should override typehints in generic @template
1 parent ed8aedb commit 4620b86

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/Ast/DtoVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private function createDtoType(Class_|Enum_ $node): void
108108
$paramType = $param->type;
109109
$paramName = $param->var->name;
110110

111-
if ($paramType === null && $classMethodComments) {
111+
if ($classMethodComments) {
112112
if ($classMethodCommentsParsed === null) {
113113
$classMethodCommentsParsed = $this->phpDocTypeParser->parseMethodParams($classMethodComments);
114114
}

tests/TypeScriptGeneratorTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,41 @@ public function nestedGenericsSimpleType() {}
685685
$this->assertMatchesGeneratedTypeScriptApi($result);
686686
}
687687

688+
public function testGenericDtoWithArrayField(): void
689+
{
690+
$code = <<<'CODE'
691+
<?php
692+
693+
use \Riverwaysoft\PhpConverter\ClassFilter\DtoEndpoint;
694+
use \Riverwaysoft\PhpConverter\ClassFilter\Dto;
695+
696+
/**
697+
* @template T
698+
*/
699+
#[Dto]
700+
class Paginated
701+
{
702+
/**
703+
* @param T[] $items
704+
*/
705+
public function __construct(
706+
public array $items,
707+
public int $totalCount,
708+
public int $pagesCount,
709+
public int $page,
710+
)
711+
{
712+
}
713+
}
714+
CODE;
715+
716+
$converter = new Converter([
717+
new DtoVisitor(new PhpAttributeFilter('Dto')),
718+
]);
719+
$result = $converter->convert([$code]);
720+
$this->assertMatchesGeneratedTypeScriptApi($result);
721+
}
722+
688723
public function testApiClientGenerationWithApiPlatformLegacyResource(): void
689724
{
690725
$code = <<<'CODE'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT!
2+
3+
import axios from 'axios';
4+
5+
export type Paginated<T> = {
6+
items: T[];
7+
totalCount: number;
8+
pagesCount: number;
9+
page: number;
10+
};
11+
12+
export type CollectionResponse<Resource extends {id: string}> = {
13+
'hydra:member': Resource[];
14+
'hydra:totalItems': number;
15+
'hydra:view': { '@id': string; 'hydra:last': string };
16+
'hydra:search': { 'hydra:mapping': any[] };
17+
'hydra:last': string;
18+
};

0 commit comments

Comments
 (0)