How to refactor a Yii-site

Hi all!

I have made a rather large and complex application with Yii, and I am planning to make a refactoring soon to get rid of messy structure, messy pieces of code and inefficient algorithms. The aim is most of all to make it easier to extend the application in the future: Thus to make a more logical division of models, controller, view parts and to encapsulate better the different objects.

Do you have any good tips or links to guides/tutorials which explains how to do a good refactoring? If possibly related to Yii?

Best regards,


Just one (obvious) tip: use automated tests. Whenever possible, write some unit tests (or functional test, if you have to) on the part of the code you want to refactor. If the tests pass before and after the refactoring, the probability you broke something is low. You may also be interested in the code coverage of your tests.

The official tutorial (The Definitive Guide To Yii) has a chapter dedicated to tests.

1 Like