rector
rector copied to clipboard
Allow AliasedObjectType adding to UseNodesToAddCollector
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.