You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Thanks for the feature request and thank you for the patience.
We've used to provide aliases in the path, but it made FQN importing twice as complex with many bug-cases poping out here and there. That's why we took a path to use FQN first.
But if you want to use alises on e.g. Doctrine annotations/attributes, you can easily create a custom Rector rule that handles Use_ imports and groups them this way. This could be achieve in no more than 50-lines and would apply on all your files at once 👍
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 useFullyQualifiedObjectType
as input, but can returnAliasedObjectType
. Moreover some annotations do not take into account thatUseNodesToAddCollector
can returnAliasedObjectType
I think that UseNodesToAddCollector must be able to accept
AliasedObjectType
as input.May be we should introduce interface for
FullyQualifiedObjectType
andAliasedObjectType
.I think that this code will be more semantic
May be I even could provide PR after some research.
The text was updated successfully, but these errors were encountered: