Search code examples
phpintellij-idearefactoringphpstormautomated-refactoring

PhpStorm: Replace string literal with class constant


I've been trying to find out how to replace a string of an FQCN with an import statement (and vice-versa). I can't work out if this feature doesn't exist or if I just can't find it.

For example, the ALT + ENTER context menu in PHPUnit when creating a mock:

context menu on a string literal

PhpStorm knows which class this is - or is this a plugin doing this?

class type hint on string literal

The opposite:

context menu on a class constant

The PHP Annotations plugin adds a nice option in the context menu - but only for Doctrine:

doctrine use class constant context menu

Is there a keyboard shortcut to achieve the same result as above but with any class string literal?


Solution

  • Php Inspections (EA Extended) plugin has an inspection and quick fix for that: ::class can be used.

    enter image description here

    enter image description here