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

Allow AliasedObjectType adding to UseNodesToAddCollector #8768

Open
pincher2012 opened this issue Jul 31, 2024 · 0 comments
Open

Allow AliasedObjectType adding to UseNodesToAddCollector #8768

pincher2012 opened this issue Jul 31, 2024 · 0 comments
Labels

Comments

@pincher2012
Copy link

pincher2012 commented Jul 31, 2024

Feature Request

I want create Rector that import missed imports for doctrine annotations for example:

declare(strict_types=1);

+use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Entity
{
}

I found out that I can add new imports via UseNodesToAddCollector. UseNodesToAddCollector can only use FullyQualifiedObjectType as input, but can return AliasedObjectType. Moreover some annotations do not take into account that UseNodesToAddCollector can return AliasedObjectType

I think that UseNodesToAddCollector must be able to accept AliasedObjectType as input.

May be we should introduce interface for FullyQualifiedObjectType and AliasedObjectType.

I think that this code will be more semantic

if ($this->shouldAddUse($phpDocInfo)) {
-    $this->useNodesToAddCollector->addUseImport(new FullyQualifiedObjectType('Doctrine\ORM\Mapping as ORM'));
+    $this->useNodesToAddCollector->addUseImport(new AliasedObjectType('ORM', 'Doctrine\ORM\Mapping'));

    return $node;
}

May be I even could provide PR after some research.

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

No branches or pull requests

1 participant