In all Java IDEs I have used, refactoring/renaming was a breeze because IntelliJ would scan the projects files and rename everything for me.
I am currently using a project where there are hundreds of references to a class spread around hundreds of files. I would like to refactor it so my Compound
class is renamed to CompoundTag
.
So instead of new Compound()
, the IDE (PhpStorm) should change it to new CompoundTag()
.
So, first I right clicked the file, went to Refactor -> Rename
:
Next, I renamed it and made sure to check these options:
Finally, after clicking refactor.. nothing happens. The file name gets changed but nothing else in the project gets refactored. PhpStorm does not even change the class name.
How can I fix this to get PhpStorm to properly refactor my files?
You have invoked Refactor | Rename
on a file.
What you did is you have renamed a file .. and possibly all references to a file. But in PHP world class name does not necessarily must be the same as file name .. and you may find quite a lot of older projects (especially those those with long history) where you may even see more than one class in a single file. WordPress is one of the popular examples. Surely, these days it's not a common practice (thanks to PSRs) but still...
It works for Java (in IntelliJ) because:
For PHP this path (rename file = rename class) is simply not yet implemented.
What you need to do for PHP ... is to invoke Refactor | Rename
on actual CLASS and not a file.
Refactoring actions are context dependant in IDEA-based IDEs .. so the same action will do different things depending if you invoked it on a file (e.g. in Project View panel) or on a some element under caret (in the Editor).
Such class refactoring can do more than just this class rename:
Some links:
P.S. Similar story with just moving files and changing namespaces -- invoke Refactor | Move
on a class/namespace and not on a file.