Bug Report/Feature request
| Subject |
Details |
| Rector version |
last dev-main |
| Installed as |
composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/a460202b-0782-4844-b547-14f975bbc2b2
<?php
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
class DemoFile
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private int $id;
#[ORM\Column(type: 'string')]
private string $name;
}
Responsible rules
AttributeKeyToClassConstFetchRector
Expected Behavior
Currently, both columns are changed so that they use the FQCN \Doctrine\DBAL\Types\Types for the type: field, even though
that class is already imported in the use statement.
I would appreciate rector to leave the first column ("id") as is and only change the second column.
Preferably it should detect the already imported class and use that.
So I want the result to look like:
<?php
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
class DemoFile
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private int $id;
#[ORM\Column(type: Types::STRING)]
private string $name;
}
alternatively, this would also work (only touch changed lines, i.e. lines that use a literal instead of a class-constant):
<?php
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
class DemoFile
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private int $id;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING)]
private string $name;
}
I know that I could use $reactorConfig->importNames(true), but that would also import all other classes/namespaces, I only want to import some of them. Or is there a possibility to limit that to specific namespace?
Bug Report/Feature request
Minimal PHP Code Causing Issue
See https://getrector.com/demo/a460202b-0782-4844-b547-14f975bbc2b2
Responsible rules
AttributeKeyToClassConstFetchRectorExpected Behavior
Currently, both columns are changed so that they use the FQCN
\Doctrine\DBAL\Types\Typesfor the type: field, even thoughthat class is already imported in the use statement.
I would appreciate rector to leave the first column ("id") as is and only change the second column.
Preferably it should detect the already imported class and use that.
So I want the result to look like:
alternatively, this would also work (only touch changed lines, i.e. lines that use a literal instead of a class-constant):
I know that I could use
$reactorConfig->importNames(true), but that would also import all other classes/namespaces, I only want to import some of them. Or is there a possibility to limit that to specific namespace?