views:

152

answers:

2

Is there any tools to check for dead code for PHP5? Something like

  • Scan classes with Reflection
  • Follow "normal" code with token_get_all() and find variables with token T_NEW and then scan for method calls.
  • Output something like classname (count of new declarations) methods (count of calls)
+1  A: 

If I remember correctly you can use phpCallGraph to do that. It'll generate a nice graph (image) for you with all the methods involved. If a method is not connected to any other, that's a good sign that the method is orphaned.

Here's an example: classGallerySystem.png

The method getKeywordSetOfCategories() is orphaned.

Just by the way, you don't have to take an image -- phpCallGraph can also generate a text file, or a PHP array, etc..

Till
+4  A: 

Would something like PHPUnit work for you? Here's a sample of an output using something I was working on:

Edit: To add a bit of clarification - this is actually a screen-grab of the HTML generated when you use Xdebug with PHPUnit. It's a bit tricky to set up; I detailed some of a how-to here and here. You can also use flags to output text, xml, json, and other formats for your coverages.

Typeoneerror