I have recently gotten involved in a project where a web-based game uses an engine written in PHP. The game works fine but could be more robust and have some more features - and the code is both old and fairly ugly.
The issue with this code (and much PHP code in general I suspect) is that it has evolved to where it is and isn't structured very nicely, has a lot of almost-identical cut/pasted pieces of code, and makes heavy use of globals even where functions are involved. Not a single unit test anywhere, of course, and the code is hard coded to use a particular DB and relies on $_REQUEST strings from the web page that calls the code.
The right thing to do would be to pull out pieces of the code as sub-functions, tidy them up and add some unit tests to make sure it continues to work, adding a few mock objects along the way. However, doing this entirely by hand is tedious and error-prone and I wonder how you do this - is there an IDE or tool that can help, for example? I would like to have a tool that can help produce a function from a defined piece of code, suggest which variables should be parameters, by value or reference, automatically add $this-> references, etc.
Is this too much to ask, or is there a good solution?
Thanks!