PhpStorm 2020.1 Help

Rename refactorings

Basics

Rename refactorings allow you to rename symbols and files with all the references to them in the code corrected automatically.

The following rename refactorings are available in PhpStorm:

  • Rename Class. The following usages are renamed:

    • Import statements

    • Qualified names of classes

  • Rename Method. The following usages are renamed:

    • All calls of the method.

    • All overridden/implemented methods in subclasses.

  • Rename Field.

Rename a symbol

  1. Select the item to be renamed.

    • To select a file, click the desired file in the Project tool window.

    • To select a symbol in the editor, place the caret at the name of the symbol to be renamed.

    • To select a symbol in the Project tool window, make sure that the members are shown, and then click the desired symbol.

    • To select a symbol in the Structure view, click the desired symbol in the Structure tool window Alt+7.

  2. Choose Refactor | Renamefrom the main menu or from the context menu or press Shift+F6.

  3. The subsequent behavior depends on the Enable in-place refactorings checkbox located in Settings/Preferences | Editor | General.

    • If this checkbox is selected, the suggested name appears right below the symbol. You can either accept suggestion, or type a new name . However, if you press Shift+F6 once more, PhpStorm will display the Rename dialog with more options.

    • If this checkbox is not selected, the Rename dialog dialog opens immediately.

    Invoke Rename refactoring

    The set of controls and their names depend on the type of the symbol to be renamed.

  4. Preview and apply changes.

  5. If PhpStorm detects the symbol occurrences in comments and strings, it suggests to extend refactoring to that usages as well:

    Rename strings

    In this case:

    • Choose Show Usages to view that usages in Find Tool Window.

    • Choose Rename Only Code Usages to apply refactoring to code usages only.

    • Choose Rename All Usages to rename both code and non-code usages.

    • Click Cancel to terminate and return back.

Rename a file or directory

  1. Select a desired file in the Project tool window.

  2. Choose Refactor | Rename on the main or context menu or press Shift+F6.

  3. In the Rename dialog that opens, specify the new filename. Select Search in comments and strings checkbox to let PhpStorm apply changes to comments and strings.

  4. Press Preview to observe possible changes in Find Tool Window. Press Refactor to proceed.

    PhpStorm finds all the occurrences of the filename and changes them respectively.

Important notes

Last modified: 30 June 2020