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.