Inline
Last modified: 18 January 2023Shortcut: Ctrl+Alt+N
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
Before
const CONSTANT = 5;function showConstant() { echo CONSTANT . "\n";}
After
function showConstant() { echo 5 . "\n";}
Inline Variable
PHP Example
Before
function sum($a, $b) { $c = $a + $b; return $c;}
After
function sum($a, $b) { return $a + $b;}
JavaScript Example
Before
Parenizor.method('toString', function () { var string = '(' + this.getValue() + ')'; return string;}
After
Parenizor.method('toString', function () { return '(' + this.getValue() + ')';}
Inline Method or Function
PHP Example
Before
function log($message) { echo $message;}log('Message');
After
echo 'Message';
JavaScript Example
Before
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;}
After
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
Position the caret at the desired symbol to be inlined.
Do one of the following:
From the main menu or from the context menu, choose Refactor | Inline.
Press Ctrl+Alt+N.
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.
note
Inlining non-static methods is not possible. As a workaround, you can apply the Make Static refactoring prior to inlining.
Thanks for your feedback!