phpnamespacesphp-cs-fixerrector

Is there a way to keep Rector from inlining class references?


I'm using the Rector ruleset UP_TO_PHP_74 to update a legacy application.

It mostly does a good job, but the problem I'm seeing a lot of is that it's changing

...
use My/Namespace/My/Classname;
...
/** @var Guestlist */
private $myVariable;

... to this inline, fully qualified class name:

private /My/Namespace/My/Classname $myVariable;

This is something I do not want. (That's why use statements exist!)

Is there a way I can tell Rector to use use statements instead of fully qualified inline references?

If not, is there a way I can tell Rector to run everything other than the rule that's doing this?

Alternatively, is there a PHP CS Fixer rule that will automatically turn these inline references back into proper use statements?


Solution

  • Try adding this to rector config:

    $rectorConfig->importNames();

    (https://getrector.com/documentation/import-names)