Skip to content

Commit

Permalink
fix: handle interface generics
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Apr 24, 2024
1 parent 1803d09 commit f8a1b9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Type/Parser/Lexer/Token/ClassNameToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function traverse(TokenStream $stream): Type
return $constant;
}

if ($this->reflection->isInterface()) {
return new InterfaceType($this->reflection->name);
}

$templates = (new ClassTemplatesResolver())->resolveTemplateNamesFrom($this->reflection->name);

$generics = $this->generics($stream, $this->reflection->name, $templates);
$generics = $this->assignGenerics($this->reflection->name, $templates, $generics);

if ($this->reflection->isInterface()) {
return new InterfaceType($this->reflection->name, $generics);
}

return new NativeClassType($this->reflection->name, $generics);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Functional/Type/Parser/LexingParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,12 @@ public static function parse_valid_types_returns_valid_result_data_provider(): i
'type' => InterfaceType::class,
];

yield 'Interface name with one template' => [
'raw' => SomeInterfaceWithOneTemplate::class . '<string>',
'transformed' => SomeInterfaceWithOneTemplate::class . '<string>',
'type' => InterfaceType::class,
];

yield 'Class name with generic with one template' => [
'raw' => SomeClassWithOneTemplate::class . '<int>',
'transformed' => SomeClassWithOneTemplate::class . '<int>',
Expand Down Expand Up @@ -1621,3 +1627,8 @@ final class SomeClassWithTemplateOfArrayKey {}
* @template TemplateB of object
*/
final class SomeClassWithFirstTemplateWithoutTypeAndSecondTemplateWithType {}

/**
* @template TemplateA
*/
interface SomeInterfaceWithOneTemplate {}

0 comments on commit f8a1b9e

Please sign in to comment.