推薦2個好用的 PHP Refactoring 重構工具
- Change Signature
- Copy/Clone
- Extract Constant
- Extract Field
- Extract Interface
- Extract Method
- Extract Parameter
- Extract Variable
- Extract Variable for Sass
- Inline
- Move Refactorings
- Pull Members up
- Push Members down
- Rename Refactorings
- Safe Delete
這邊以 Extract function 來示範:
Before | After |
---|---|
<?php
if ('POST' != $_SERVER['REQUEST_METHOD'])
{
header('Allow: POST');
header('HTTP/1.1 405 Method Not Allowed');
header('Content-Type: text/plain');
exit;
}
?>
| <?php
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;
}
?> |
只要滑鼠選取要提取的 function,按下 Extract Method 就完成了!實在是有夠迅速神奇!備註:PhpStorm 是付費軟體(個人版 US $ 99)
如果是要免費開源的,這一套算是最好用的了,不過目前仍在 alpha 版本階段。
可做到以下重構:
- Extract Method
- Rename Local Variable
- Convert Local to Instance Variable
- Rename Class and Namespace
- Optimize use statements
並且 Sublime Text3 有對應支援的套件 lucacri/PhpSimpleRefactor
但是目前只支援以下兩種重構方法:
- Extract method
- Rename local variable
留言
張貼留言