top | item 24867185

(no title)

dkarlovi | 5 years ago

Roughly in the order you should do it. Hopefully it's at least PHP 5.3 code:

1. Definitely get a PHP IDE: https://www.jetbrains.com/phpstorm/

2. Get a step debugger and hook it in: https://xdebug.org/

3. Fix the code style: https://github.com/FriendsOfPHP/PHP-CS-Fixer

4. Run the code through some static analysis tools https://phpstan.org/ https://psalm.dev/

5. Upgrade the code with an AST fixer (might help you update to newer PHP version): https://github.com/rectorphp/rector

6. Add tests to it: https://phpunit.de/

7. Run mutation tests: https://infection.github.io/

The "0 budget" is rough, though.

discuss

order

eitland|5 years ago

In addition:

- Make sure you have version control. So easy to do these days, so often forgotten.

- don't think that the steps above must be done in order, right now.

- dkarlovi mentions tests. Start with 1.) smoke tests like simple selenium tests or something like that. You'll find lots of vate towards it if you look and I admit it has issues but for simple projects like this that doesn't change much it should be fine. Of course of you find something better use that.

- one of the most important things about a good IDE is being able to refactor confidently so you can rename variables to something reasonable as you figure out what they really are.

- the book "refactoring legacy code" might be the best programming book I've read.

propelol|5 years ago

I tried searching for "refactoring legacy code" but I couldn't find it. Who's the author?

LeonM|5 years ago

If you do #1, you'll get #3 and #4 for free, and full integration of #2 and #6 :-) Best 80 bucks you can ever spend if you write PHP.

My basic procedure when inheriting legacy code is:

- Load the project in phpstorm

- Perform autoformatting so it becomes readable

- Run code inspection to find any obvious issues the original author missed

- Write tests in phpstorm, if not already exists

- Run the code with xdebug, step through it

AdrianB1|5 years ago

All good advice for the average PHP developer, but I think it is overkill for someone that is starting with PHP just to keep alive a very old app.

Adding tests for an app with no documentation requires a lot of effort.

dkarlovi|5 years ago

Of course, that's why the list is sorted, he might never make it pass 1 :)

mgkimsal|5 years ago

> Adding tests for an app with no documentation requires a lot of effort.

code tests yes. Assuming it's a web app, probably not too hard. Get something that records the browser interactions, and do the common tasks people do (log in, click links, make a report, etc). Having general things like that automated to ensure you can run them repeatedly to make sure basic stuff didn't break unexpectedly will help provide some confidence when making changes.