Lately I have been adding new and new features to existing application and now came time when I have to play with some seriously old code. I mean – really old, forgotten and never refactored code. It’s just there, it’s working and nobody dares touching it. So before I started I need to prepare myself for the battle.
if you are in need of refactoring some critical part of the system the big chance is that this critical part doesn’t came with any tests (life, so to say). There is also a big chance that the code is basically impossible to test with unit testing – write some integration tests instead. As they say – any kind of test are better that none tests. You can use anything that works for you (for example BDD tool like behat).
install PHP_CodeSniffer, PHP Mess Detector, PHP Copy/Paste Detector and PHP_Depend (phpmd requires it so probably at this point you’ll have it installed anyway) – these tools will be very useful – trust me
you can integrate your tests/code checks with phpUnderControl that is extending CruiseControl – prepare your build file according to manual (you may want to exclude some directories for each tool, also if you code base is old I would stick with PSR-1 for the start as the code standard because PSR-2 check will likely to kill you on sight)
Bonus: some interesting results of phpmd ran just for two files :) (methods/class names blanked).
1 2 3 4 5 6 7 8 9