简体   繁体   English

使用PhpStorm的重构命令有多安全

[英]How safe is it to use PhpStorm's refactoring commands

I have some PHP code that is does not have good test coverage and is not easily testable in its current state. 我有一些PHP代码没有很好的测试覆盖率,并且在当前状态下不容易测试。 If I use commands from the refactor menu of PhpStorm, and make no other changes, how sure can I be that this won't change the behaviour of my application? 如果我使用PhpStorm的重构菜单中的命令,并且没有进行其他更改,那么我如何确定这不会改变应用程序的行为?

How safe are other automatic refactoring tools? 其他自动重构工具的安全性如何?

My understanding is that these tools will apply static analysis and could only cause changes to behaviour if the application does something very weird like depending on the output of debug_backtrace() 我的理解是,这些工具将应用静态分析,并且仅在应用程序执行某些非常奇怪的操作(取决于debug_backtrace()的输出)时才会导致行为更改。

The (overly) simple answer is it's no better or worse than manually refactoring. (过度)简单的答案是,它不比手动重构更好或更糟。

If you have good tests then it's safe. 如果您进行了良好的测试,那将是安全的。 If you don't then it's not. 如果您不这样做,则不是。

I would say do not do any refactoring without having unit tests for each function being refactored. 我要说的是,没有重构每个功能的单元测试,就不要进行任何重构。 Refactoring should not break unit tests, if it does then you haven't refactored it, you've changed it. 重构不应破坏单元测试,如果确实如此,那么您还没有重构它,就已经对其进行了更改。

I have been bitten by PhpStorms refactoring tools in weird ways in the past, even resulting in broken syntax. 过去,我曾经被PhpStorms重构工具所折服,甚至导致语法错误。 But, that was a long time ago, the tools have moved on, and it's always easy to go back a step if you're methodically committing changes to your SCM. 但是,那是很久以前的事,工具已经发展了,如果您有条不紊地对SCM进行更改,那么退一步总是很容易的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM