Test, test, and test again

There is no way around this, in order to refactor code, you need a solid set of tests. Refactoring code may well reduce the chances of introducing bugs, but changing the design of code introduces a significant amount of chances to introduce new bugs.

Unintended side-effects will occur during refactoring, where classes are tightly coupled, you may well find making a minor change to one function leading to a negative side-effect in a completely separate class.

Good refactoring effects require good tests. There is simply no way around this.

In addition to this, from a more political standpoint, some companies which have encountered the bad effects of repetitively bad refactoring efforts may become reluctant to refactor code; ...

Get Mastering PHP Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.