Move Static Member refactoring for PHP in PhpStorm
With the new Move Static Member refactoring in the PhpStorm 7 EAP, we can move static fields and methods to another type. For example when classes contain static methods that are nothing but utility methods, we can move them into a separate type.
The PHPExcel open source project has such a class: PHPExcel_Cell. It contains logic for cells in a spreadsheet as well as several utility methods that convert cell coordinates. Let’s move some of them into a new class: PHPExcel_CellUtils. In the editor we can place the caret on any static method and invoke the Move Static Member refactoring by pressing the F6 key.
After searching the type we want to move these members to, select the methods and fields that should be moved. We can refactor immediately, or use the Preview button to see the changes that will be performed.
PhpStorm will search all references of these static members and make sure they are updated. The IDE will notify us about potential problems as well. Using the Preview button, we can clearly see all occurrences where the methods selected earlier are used and where the Move Static Member refactoring will apply. Click Do Refactor to perform the changes.
Give PhpStorm 7 EAP a try and let us hear your thoughts in the issue tracker, the comments below or in our forums!
Develop with pleasure!
– JetBrains PhpStorm Team
Subscribe to Blog updates
Thanks, we've got you!