PhpStorm 2021.1 Help

Extract Method Dialog

Refactor | Extract | Method
Ctrl+Alt+M

The title of the dialog may change to Extract Function:

  • In the JavaScript context.

  • In the PHP context, when the code selection is made inside a function or a script.

ItemDescription
NameIn this field, specify the name of the function or method to be generated on the basis of the selected source code.
VisibilityIn this area, specify the visibility scope of the method to be generated. The available options are:
  • Public

  • Protected

  • Private

This area is available only in the Extract Method dialog when refactoring is invoked from a method of a PHP class.

Declare staticSelect this checkbox to have a static method created.
  1. If the new method cannot be declared static, or, vice-versa, can be created only as a static method, the Declare Static checkbox is disabled.

  2. This checkbox is available only in the Extract Method dialog when refactoring is invoked from a method of a PHP class.

Declare functional expressionSelect this checkbox to have the new function defined through a function expression, for example, new_method = function().

The checkbox is only available when refactoring is invoked in the JavaScript context.

Output variable(s)This read-only field displays the name of the variable through which the output of the new method/function will be passed to the calling method/function. Depending on your choice in the Return output variable(s) through area, this variable either will be used in a return statement or will be declared as the passed by reference parameter of the new method/function.
Return output variable(s) throughIn this area, specify the way in which the new method or function will return the output variables to the callee.
  • Return statement- select this option to have the output variables returned by value. If the Output variable(s) read-only field shows exactly one output variable, it will be used as the return value. If the selection outputs several variables, these variables will be returned as an array.

  • Parameter(s) passed by reference- select this option to have the output variables returned by reference. PhpStorm will generate a method/function without a return statement. Instead, the output variables will be added to the set of input parameters in the method/function declaration. The names of these variables will be prepended with an ampersand &.

ParametersIn this area, specify the parameters to be passed to the new method/function. If necessary, rename the parameters by double-clicking the corresponding parameter lines and entering new names.
Move Up/DownUse these buttons to change the order of the parameters.
Replace tail "break/continue" statements with return statementsSelect this checkbox to have PhpStorm transform tail break or continue statements if the selection contains any.
Signature previewIn this read-only field, view the declaration of the new method.
Last modified: 08 March 2021