Search code examples
phpstormphpdoc

How to replace FQN in PHPDoc with short name (with use)?


How can I automatically replace FQN in all files?

Before:

/**
 * @param \app\models\Test $test
 */

After:

use app\models\Test;

/**
 * @param Test $test
 */

Solution

  • If you have not imported that class yet (no use statements for that class) then it's controlled by PHP | Code Style | Fully qualified name usage inspection.

    enter image description here

    If it's already imported but you still have FQN references and want to simplify them then it's PHP | Code Style | Fully qualified name usage inspection.

    enter image description here


    You can run Code | Inspect Code... and apply offered fixes from there: they could be offered for 1 place only as well as for the whole thing at once (fix will be applied to the whole file or all selected files) -- not every inspection offers "batched" fix.

    enter image description here


    When doing it manually via Alt + Enter menu (or light bulb if using mouse).

    Not yet imported class case:

    enter image description here

    Already imported class case:

    enter image description here