PhpStorm
 
Get PhpStorm

Extract method

Last modified: 05 December 2024

The Extract Method refactoring lets you take a code fragment that can be grouped, move it into a separated method, and replace the old code with a call to the method.

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.

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