PhpStorm 2018.3 Help

Inline

PhpStorm provides the following inline refactorings:

  • The Inline Variable refactoring replaces redundant variable usage with its initializer. This refactoring is opposite to Extract variable.

  • The Inline Method refactoring results in placing the method's or function's body into the body of its caller(s). This refactoring is opposite to Extract method. You can opt to:
    • inline all occurrences of the method, and delete the method,

    • inline all occurrences of the method, and retain the method,

    • inline a single occurrence, and retain the method.

Inline Variable

PHP Example

Before

After

function sum($a, $b) { $c = $a + $b; return $c; }

function sum($a, $b) { return $a + $b; }

JavaScript Example

Before

After

Parenizor.method('toString', function () { var string = '(' + this.getValue() + ')'; return string; }

Parenizor.method('toString', function () { return '(' + this.getValue() + ')'; }

Inline Method or Function

PHP Example

Before

After

function log($message) { echo $message; } log('Message');

echo 'Message';

JavaScript Example

Before

After

function sum(a, b){ return a + b; } function multiplication(a, b){ c = sum(a, b); d = c * c; return d; } function division(a, b){ result = sum(a, b) / multiplication(a, b); return result; }

function multiplication(a, b){ c = a + b; d = c * c; return d; } function division(a, b){ result = a + b / multiplication(a, b); return result; }

Perform inline refactoring

  1. Place the caret in the editor at the desired symbol to be inlined.

  2. Do one of the following:
    • On the main menu or on the context menu, choose Refactor | Inline.

    • Press Ctrl+Alt+N.

  3. When inlining a variable, confirm the refactoring in the Inline dialog. When inlining a method, specify the inlining options in the Inline Method dialog.

  4. Preview and apply changes.

Last modified: 18 March 2019

See Also