Extract method
The Extract Method refactoring lets you take a code fragment that can be grouped, move it into a separated method, and replace the old code with a call to the method.
In the JavaScript context, this refactoring always results in a function.
In the PHP context, the result of applying the Extract Method refactoring depends on the location of the selected code fragment:
If the selection is made inside a method of a class, the refactoring extracts a method.
If the selection is made inside a function or a script, the refactoring extracts a function.
Select a code fragment you want to extract to a method.
Press CtrlAlt0M or go to Refactor | Extract | Method in the main menu.
Alternatively, on the floating toolbar that appears when a code fragment is selected, click Extract and select Method.
Press Enter to apply the change.
By default, this extract refactoring will be applied in the editor via in-line controls. To change your settings to apply the refactoring via a modal, open the Settings dialog (CtrlAlt0S) , go to Editor | Code Editing, and in the Refactorings area select In modal dialogs.
Gif
tip
To reverse the Extract Method refactoring, press CtrlAlt0N to invoke the Inline refactoring.
public function init()
{
$this->_router = $this->getFrontController()->getRouter();
}
public function init()
{
$this->_router = $this->getRouter();
}
/**
* @return mixed
*/
public function getRouter()
{
return $this->getFrontController()->getRouter();
}
if ('POST' != $_SERVER['REQUEST_METHOD']) {
header('Allow: POST');
header('HTTP/1.1 405 Method Not Allowed');
header('Content-Type: text/plain');
exit;
}
function printEmptyHeader()
{
header('Allow: POST');
header('HTTP/1.1 405 Method Not Allowed');
header('Content-Type: text/plain');
}
if ('POST' != $_SERVER['REQUEST_METHOD'])
{
printEmptyHeader();
exit;
}
Thanks for your feedback!