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: handle interface generics #535

Merged
merged 1 commit into from
Apr 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {}