Refactoring for Class Members in PhpStorm 6: Pull Up and Push Down

As you work on a big project, you often face the need to refactor your code to maintain it properly. Likewise, there are many situations when you start to add functionality from the bottom of the class hierarchy and then realize it can be also used in more common cases (otherwise some parts of your code may become obsolete for the parent class but still be valid for one of its children).

To fix this, you copy a method or field from one class, paste it into another and fix internal references in the member. This isn’t so difficult, yet rather annoying if done over and over.

With PhpStorm, both of these tasks become much easier. To help you move class members thought the hierarchy, the IDE offers you two helpful refactorings: Pull Members Up and Push Members Down.

Pull Up Refactoring
To perform this refactoring, place the caret inside the class and choose Refactor | Pull Members Up… in the menu. The Pull Members Up dialog will display:

Now, configure the list of members to be pulled up and the target class. If no conflicts are found, the refactoring will be performed immediately, otherwise you’ll need to resolve the conflicts.

That’s all – PhpStorm will take care of all other actions for you. Here’s how it looks after the refactoring is complete:

Push Down Refactoring

Push Down refactoring looks very similar: place the caret inside the class and choose Refactor | Push Members Down… in the menu.

You also can choose the list of class members to be pushed down, and they will be moved to the direct child classes.

We hope you find these refactorings useful in your daily work. If you find any bugs or come up with any feature requests related to Pull Up/Push Down, please file in our issue tracker.

Develop with pleasure!
– JetBrains Web IDE Team.

This blog is permanently closed.

For up-to-date information please follow to corresponding WebStorm blog or PhpStorm blog.

 
This entry was posted in Cool Feature, PhpStorm and tagged , , , . Bookmark the permalink.

4 Responses to Refactoring for Class Members in PhpStorm 6: Pull Up and Push Down

  1. El Torro says:

    Plz fix this Error http://youtrack.jetbrains.com/issue/WI-13319

    Fix Version 6 ?

  2. Maxim Makhankov says:

    The planned Fix version is 6, but the issue is still in the Open state and it might be postponed for 6.0.x. We consider this issue as important (note, the priority is “Major”).
    Feel free to vote for this ticket to be informed about the progress.

  3. Brad W says:

    Is there room for leaving a skeleton of the pushed method on the parent?
    Seems like that would be a common use case.

Comments are closed.