Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cleanup unused code in a large php project

Is there any monitoring, analysis tools that would facilitate the cleaning up of dead files , variables , functions and refactoring of a large , relatively messy php project/framework?

like image 350
Matoeil Avatar asked Aug 01 '26 13:08

Matoeil


2 Answers

Facebook's HipHop also has a very fast static code analyzer which will help. Etsy's Nick Galbreath gives a nice presentation on this at http://www.slideshare.net/nickgsuperstar/static-analysis-for-php

like image 129
Promethius Avatar answered Aug 04 '26 02:08

Promethius


If the problem is cleaning up dead code, first you have find dead code.

You can use test coverage tools (my company offers one of these) to find out what code is likely to be dead. Exercise lots of functionality either via unit tests or by simply running the application for a day; no coverage of method X means X is probably dead.

Dead variables are harder; you need data access coverage information. I don't know of any such tools for PHP.

I don't know of any static analyzers that will reliably tell you if code/variables are dead. (HipHop, mentioned in another answer, might be able to do this for some methods, and especially for local variables, but eval can cause any function to be called or any variable to be referenced so it is hard to get this right in PHP).

Then you can decide if you want to remove the dead code, or retain it to improve future evolution.

.

like image 33
Ira Baxter Avatar answered Aug 04 '26 02:08

Ira Baxter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!