PhpStorm 7.1.0 Web Help

The Extract Field refactoring declares a new field and initializes it with the selected expression. The original expression is replaced with the usage of the field.

Example

Before After
                  public static function find($params){
    if (isset($params['param_query'])) {
        $result = MyDatabase::execute($params['param_query']);
        }
    }

public static function findAll($params){
    if (isset($params['param_query'])) {
        $result = MyDatabase::executeAll($params['param_query']);
        }
    }
                        
                  public static
                  $query = 'param_query';

public static function find($params){
    if (isset($params[self::$query])) {
        $result = MyDatabase::execute($params[self::$query]);
        }
    }

public static function findAll($params){
    if(isset($params[self::$query])){
        $result = MyDatabase::executeAll($params[self::$query]);
        }
    }
                        
To extract a field using the dialog box

If the Enable in place refactorings check box is cleared on the Editor settings, the Extract Field refactoring is performed by means of the Introduce Field dialog box.

enableInplaceRefactoringCleared

  1. In the editor, select the expression or variable to be replaced with a field, or just place the cursor within such an expression or variable declaration.
  2. In the main menu, or the context menu of the selection, choose Refactor | Extract Field, or press Ctrl+Alt+FCtrl+Alt+FCtrl+Alt+FCtrl+Alt+FCtrl+Alt+FCtrl+Alt+FShift+Alt+ECtrl+Alt+FAlt Command FAlt Command FAlt Command F.
  3. In the Expressions pop-up menu, select the expression to be replaced. Note that PhpStorm highlights the selected expression in the editor.
  4. In the Extract Field Dialog dialog that opens, specify the type and name of the new field.
  5. To automatically replace all occurrences of the selected expression (if it is found more than once), select the option Replace all occurrences.
  6. Click OK to create the field.

See Also

Reference:

Web Resources: