Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analyzing a PHP program [closed]

Tags:

php

I have been giving a PHP program to work on. However, this program has been worked on for years by several diffrent people. Things have been removed and added over time. But most of the files are still there.

I was wondering is there is a tool out there that can analyze a PHP program. feed it index.php for example and this tool will check and see witch files are called and used so i can remove all the dead wood that is no longer beeing used.

I was planning on writing it myself, but someone else might already have done something like this.

Any suggestions are welcome, Thx! Mike

like image 723
Mike van Heugten Avatar asked Dec 19 '11 07:12

Mike van Heugten


2 Answers

As deceze mentioned you cannot guarantee to find all referenced files as they may be dependent on user input. However the simplest way is to use a grep tool (there is a "windows grep" application you can download, if that's your platform) and find all occurrences of "include" and "require". If you come accross the situation mentioned by deceze (include or require followed by a variable name) the file needs manual inspection, but if there is a file name specified, you can add that to the "used list".

Perhaps not the most effective solution, but fast and intuitive.

like image 118
C.Evenhuis Avatar answered Sep 24 '22 21:09

C.Evenhuis


You have couple options, one to use xdebug and basically debug your application, while you are stepping through you ll find the files being used.

Another is brute force:)) start deleting files one by one and check the app if it s broken or not. if there is a lot to test, this might take a while.

And if you are searching for an app, search for dependency checker, there are corps that uses these kinda apps to check dependencies between services, like amazon.

like image 26
DarthVader Avatar answered Sep 21 '22 21:09

DarthVader