Dependencies graph for large PHP application

9.5k views Asked by At

I've recently inherited a large PHP application with NO objects/modules/namespaces...only a lot of files containing functions.

Of course, there is a LOT of dependencies (and all files and almost always included).

I'm looking for a tool that could analyse the files and generate a dependencies graph. It would then be easier to detect independent files/set of files and re-factor the whole thing.

So far the best solution I've found would be to write a CodeSniffer sniff to detect all functions calls and then use that to generate the graph.

It seems something useful for other, so I'm sure tools already exists for it.

What would you recommend ?

2

There are 2 answers

0
Eugen Mihailescu On

I could recommend a lightweight project I wrote few days ago. Basically I had a 300+ files PHP project and I wanted to detect what files do these files require/include and vice-versa. Moreover, I wanted to check for each individual file what files does this file requires/includes (directly or indirectly, ie. via file inheritance) and vice-versa: what are the files that include this particular file. For any combination of these I wanted an interactive dependency graph (base on file inclusion and not on class/function calls/usage).

Check out the project's sandbox and its source code.

Note that the whole thing was written in only 2 days so don't judge it too harsh. What's important is that it's doing its job!

1
mcuadros On

I think that the best solution is use a doc generat + grapviz, PHPDocumentor looks to have a Grapviz extension at https://github.com/phpDocumentor/GraphViz

This is a example made with PHPDocumentor: http://demo.phpdoc.org/Clean/graphs/classes.svg

Too you can use a hierarchical profiler like xhprof (https://github.com/facebook/xhprof), this can draw a tree of all call to functions from a execution.

A example form xhprof draw done by Graphviz A example form xhprof draw done by Graphviz