I have been given an old website to add a new feature to with an eye to migrating to Laravel in the longer term.
It's around 70,000 lines of PHP4/early 5 code, no comments to speak of, everything is shared state and global (just newing up a class can modify other classes, add menu entries to the page, update the DB).
Some classes are 4-5000 lines long, there are no parameters passed to any methods - everything reads&writes from a shared global state, require_once's everywhere, there are variables used by reference so you're not quite sure what they are and changing them breaks the whole site (for instance there was a variable '$x' that didn't seem to be used in a method I was looking at - I commented it out to see what happened and every date on every page started returning NULL).
Oh, and no tests, obviously ;-)
So my plan is to add the new feature as separately as I can from the current code using autoloading, small classes, unit tests etc and introduce a small ORM where I can while trying to get a handle on how it hangs together. Once that's done, start going through the old code and refactor it in small chunks (autoloading, breaking up the huge methods, reducing the global state where possible).
The current code is very hard to reason about so writing tests for it is quite difficult as I've really no idea what it should be doing and there are side-effects everywhere - so some avenues are blocked on that front. It also has to work in PHP 5.3 so quite a lot of useful libraries are unavailable to me (as an aside, there are a remarkable number of libraries documented as working with 5.3 which actually use features of 5.4 - fun!)
Anyway - just wondering if anyone else has been here before and could share any tips, strategies etc? I've got a copy of Paul M. Jones 'Modernizing Legacy Applications In PHP' book coming Real Soon Now(TM) which I'm hoping will have some useful pointers, but thought I'd ask you all too.