Dependencies graph for large PHP application

Loïc Février picture Loïc Février · Sep 10, 2013 · Viewed 7.4k times · Source

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 ?

Answer

mcuadros picture mcuadros · Oct 10, 2013

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