Working with Refactoring

The purpose of this tutorial is to teach you how to refactor your code to easily rename and move files and elements without damaging your projects or severing the link between referenced items, as well as creating the necessary links between PHP elements in separate files.

Purpose and Usage

The Refactoring feature allows you to:

Refactoring should be used when you are reorganizing your project and changing names and locations of files and elements.

Note:

Refactoring will only work from within PHP Explorer view and not from Navigator view.

Back to Top

Renaming / Moving Files

Renaming a file

Renaming a file will result in the automatic renaming of all instances where that file is referenced within the project.

 

 

Instructions on how to complete a procedure

This procedure demonstrates how to Rename a file:

  1. Create a PHP file, called RenFile1, with the following code:

<?
$a = 5;
?>

  1. In the same project, create a second PHP file, called RenFile2, with the following code:

<? require(RenFile1.php);$a = 8;?

Note:

Ensure you delete the PHP tags that are inserted by default when creating a new PHP file before pasting in the code.

  1. Save both files.

  2. In PHP Explorer view, right-click RenFile1 and select Refactor | Rename – or- select it and go to Refactor | Rename from the Main Menu.
    A Rename File dialog will appear.

  3. In the Rename File dialog box, rename RenFile1 to RenFile3.

  4. Check the "Update references" box and click Preview.

  5. In the Preview window, scroll through the changes and note that, as well as the name of the file itself being changed, the reference to the file in RenFile2 will also have been changed.

  6. Press OK to apply changes.

The reference to RenFile1 in RenFile2 will have been updated to:

require(RenFile3.php);

in order to reflect the changes in the file name.

Moving a file

Moving a file will result in the automatic updating of all instances where that file is referenced within the project to reflect its change of location.

 

 

Instructions on how to complete a procedure

This procedure demonstrates how to move a file:

  1. Create RenFile1 and RenFile2 as described in steps 1 to 3 underRenaming a File, above.

  2. Within the same project, create an additional folder called RenFolder.

  3. In PHP Explorer view, right-click RenFile1 and select Refactor | Move -or- select it and go to Refactor | Move from the Main Menu.

  1. In the Move dialog, select RenFolder.

  2. Click Preview.

The Preview windows will display the changes that the move will apply to your script. Note that RenFile1's new location will automatically be updated in the reference to it in RenFile2.

  1. Click OK to execute the Move.

 

Back to Top

Renaming Elements within a File

All PHP Elements (e.g. classes, interfaces, functions, methods) can also be renamed and refactored from within the editor window.

 

 

Instructions on how to complete a procedure

This procedure demonstrates how to use the Rename Elements feature:

  1. Create 2 files (RenFile1 and RenFile2) as described in steps 1 to 3 under "Renaming a File", above.

  2. In the editor window of RenFile2, highlight the variable "a" on line 3.

  3. Right-click and select Refactor | Rename -or- click Alt+Shift+R.

  4. In the Rename Global Variable dialog box, rename the variable to b.

  5. Check the "Update textual occurrences" box and click Preview.

  6. In the Preview window, scroll through the changes and note that occurrences of variable "$a" will be changed in RenFile1 as well as in RenFile2.

  7. Press OK to apply changes.

 

Back to Top

Back to Top

 

 

Related Links:

Refactoring

Using Refactoring

Renaming Files

Renaming Elements

Organizing Includes  

Refactor Menu

 

 

Back to Top

©1999-2013 Zend Technologies LTD. All rights reserved.