PhpStorm 2022.1 Help

Inline

PhpStorm provides the following inline refactorings:

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

    You can opt to do any of the following:

    • Inline all occurrences of the constant, and delete the constant,

    • Inline all occurrences of the constant, and keep the constant,

    • Inline a single occurrence, and keep the constant.

  • The Inline Variable refactoring replaces redundant variable usage with its initializer. This refactoring is opposite to Extract/Introduce 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 do any of the following:

    • Inline all occurrences of the method, and delete the method,

    • Inline all occurrences of the method, and keep the method,

    • Inline a single occurrence, and keep the method.

Inline Constant

const CONSTANT = 5; function showConstant() { echo CONSTANT . "\n"; }
function showConstant() { echo 5 . "\n"; }

Inline Variable

PHP Example

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

JavaScript Example

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

Inline Method or Function

PHP Example

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

JavaScript Example

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. Position the caret at the desired symbol to be inlined.

  2. Do one of the following:

    • From the main menu or from 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 or constant, specify the inlining options in the Inline Method/Inline Constant dialog.

    You can opt to do any of the following:

    • Inline all occurrences of the method or constant, and delete the method or constant,

    • Inline all occurrences of the method or constant, and keep the method or constant,

    • Inline a single occurrence, and keep the method or constant.

  4. Preview and apply changes.

Last modified: 30 November 2021