PhpStorm
 
Get PhpStorm
You are viewing the documentation for an earlier version of PhpStorm.

Extract method

Last modified: 04 October 2023

When the Extract Method refactoring is invoked, PhpStorm analyses the selected block of code and detects variables that are the input for the selected code fragment and the variables that are output for it.

The detected output variable is used as a return value for the extracted function.

In the JavaScript context, this refactoring always results in a function.

In the PHP context, the result of applying the Extract Method refactoring depends on the location of the selected code fragment.

  • If the selection is made inside a method of a class, the refactoring extracts a method. This case is applicable when you are using PHP 5.0 and later.

  • If the selection is made inside a function or a script, the refactoring extracts a function.