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

[NodeTypeResolver] Move namespaced name check into specific NameTypeResolver #6093

Closed
wants to merge 7 commits into from

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Jul 1, 2024

Ref review comment #6089 (comment)

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

@TomasVotruba
Copy link
Member

I see. Could you add failing fixture to verify this is needed?

@samsonasik
Copy link
Member Author

I will try.

@samsonasik
Copy link
Member Author

I added test for existing class short name node short name ac85ebf

without this, it will got non existing object type, which actually exists

+Rector\StaticTypeMapper\ValueObject\Type\NonExistingObjectType Object #5255 (
+    'className' => 'AnotherClass',

as pointed to Rector\Tests\NodeTypeResolver\Source\AnotherClass

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I think it is ready.

@TomasVotruba
Copy link
Member

TomasVotruba commented Jul 1, 2024

I've just release new Rector 1.2.0 with this feature.
Closing for now to keep focus, let's wait for real-life feedback and fixtures :)

@TomasVotruba TomasVotruba deleted the move-namespaced-name branch July 1, 2024 14:56
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.

3 participants