Refactoring
The Refactoring feature allows you to:
- Rename and move files and elements within those files, while maintaining the links between the items. Once an element or file has been renamed or moved, all instances of that item within the project will be automatically updated to reflect its new name / location.
- Extract variables - Creates new variables for expressions.
Creates a new variable assigned to the expression currently selected and replaces the selection with a reference to the new variable.
Example:
Implementing an extract method refactoring on the variable $my_form in the following code:
Will result in the following code being created (the changes have been highlighted):
- Extract Methods - Creates a new method to replace all occurrences of a selected fragment of code.
Martin Fowler, the creator of the Refactoring concept, defines it as the following:
"Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring."