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