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

Remove direct Name support from getType(), as name is never a type #6089

Merged
merged 1 commit into from
Jun 30, 2024

Conversation

TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Jun 30, 2024

The #5947 introduced a direct Name to type conversion in getType(). The Name is not a type, but only a class-string.

Using Name as a type leads to bugs: #6087

We should resolve only exprs or type nodes.

@TomasVotruba TomasVotruba changed the title Remove direct Name support rom getType(), as name is never a type Remove direct Name support from getType(), as name is never a type Jun 30, 2024
@TomasVotruba TomasVotruba merged commit 3365513 into main Jun 30, 2024
33 checks passed
@TomasVotruba TomasVotruba deleted the tv-remove-name-from-type branch June 30, 2024 18:01
@samsonasik
Copy link
Member

Name can be a type, and we have NameTypeResolver

final class NameTypeResolver implements NodeTypeResolverInterface
{
/**
* @return array<class-string<Node>>
*/
public function getNodeClasses(): array
{
return [Name::class, FullyQualified::class];
}

The namespaced_name attribute was only working on NullableType type, thats why PR #5947 added to work recursively to get short name support, eg: alias name, which never be FullyQualified.

The getType() method works on recursive way in nodes:

public function getType(Node $node): Type
{
if ($node instanceof NullableType) {
$type = $this->getType($node->type);

For Expr only, there is getNativeType() for Expr only, but for getType(), there is list supported type resolvers:

https://github.com/rectorphp/rector-src/tree/main/src/NodeTypeResolver/NodeTypeResolver

@samsonasik
Copy link
Member

I created PR:

to move it to NameTypeResolver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants