tags:

views:

94

answers:

6

I have inherited a very messy project. There are at least 3 versions that I can tell in it.

Is there a utility that can trace the PHP code from the main index.php so that I can figure out what isn't being used and what is, or am I stuck doing a manual cleanup?

Thanks

*Update*

I don't think I've been clear about what I'm looking for, that or I'm not understanding how the products mentioned work. What I'm looking for is something that can run on a folder (directory) and step through the project and give me a report of which files are actually referenced or used (in the case of images, CSS, etc).

This project has several thousand files and it's a very small project. I'm trying to clean it up and when I do a "search in files" in my IDE I get 3 or 4 references and can't easily tell which one is the right one.

Hope that makes it a little clearer.

+1  A: 

There are several utilities that can do this, what first comes mind is Zend Studio's built in Optimizer that will run through your files and issue notices on a per file basis, including unused variables, warnings, etc. Alternatively, you can run your program in E_STRICT and PHP will notify you of some of your issues.

asnyder
+1  A: 

Be very careful of such cleanup tools, especially in PHP or Javascript. They work reasonably well in languages like Java, but any language that allows Eval() can trip an automated tool up, sometimes in devilishly clever ways, depending on how clever the original code developer thought they were.

Paul McMillan
A: 

You might want to check xdebug's code coverage, possibly as an auto_append. However, itś rather limited and it would require you to have either 100% test-cases (which I doubt as you say the project is a mess), or the tenacity to go through every possible action on the site, and even then you'll have to apply good judgement whether you can remove a portion of code because it isn't used, or leave it there because a certain condition just hasn't been met yet in your cases. On a side note: stepping through the code with xdebug's remote debugger has really helped me in the past to quickly get the different mechanisms & flows in unknown projects.

Wrikken
+1  A: 

Cross referencing software really lets you explore which functions are used for what.

PHPXref is quite good..

For example Yoast used it to cross reference the Wordpress PHP code. Take a look at the Wordpress example of how powerful it is.

For example, start by browsing the WP trunk. Click on some of the file names on the left and observe how the required files are listed, along with defined classes and methods, etc., etc.

Peter Ajtai
+1  A: 

You need the inclued extension. You can generate include graphs using GraphViz, see below for example code.

There are some useful examples on PHP.net: http://www.php.net/manual/en/inclued.examples-implementation.php

bobdiaes
A: 

I would try opening the whole project in NetBeans PHP, its a great tool which we use for huge projects. You can easily see warnings and notifications and also follow usage of functions/classes easily. Try it! I would recommend against automatic cleanups and the likes. Even if the code seems to work afterwards, I wouldnt sleep very well at night...

matzee