PHP code analyzer to determine classes/extensions used
Asked Answered
F

2

6

Problem

I have a legacy codebase I need to analyze and determine dependencies. Particularly the dependencies on classes (internal/external) and extensions (Memcache, PDO, etc).

What I've Tried

I have reviewed the tools listed in Is there a static code analyzer for PHP files?. Unfortunately, this post is dated and most of the promising tools like phpCallGraph no longer work.

My thought was to analyze the code lexically and look for class tokens. Reviewing a list of these would at least allow me to visually determine dependencies. However finding OtherClass in the following code may be complex:

$classname = 'OtherClass';
echo $classname::doubleColon();

In the end, I doubt I'm the first to need this. I'm sure a tool or combination of tools exist to provide what I need. So I'm asking the SO community before writing this myself.

Update

Ideally this tool will analyze multiple files with complete code coverage. As such, tools like Xdebug, while great, are not solutions to this exact problem.

Fayre answered 26/10, 2012 at 14:17 Comment(0)
D
3

Instead of phpCallGraph you could use Gopal Vijayaraghavan's inclued extension which in combination with Graphviz gives you a nice looking graph of all included files for a certain execution path.

Example:

enter image description here

Moreover, I'd recommend Xdebug (a PHP debugger) which offers a profiler that outputs data consumable by Valgrind. Use the debugger with a compatible IDE to follow the execution path (which helped me a lot to wade thru e.g. Drupal's massive call-stack).

Combine both and you should get a fairly thourough overview.

EDIT

Searched the web and found nWire for PHP - an eclipse plugin that looks like it could be the right tool for you (30 day free trial which should be enough to give you a head start).

Diluvial answered 26/10, 2012 at 14:28 Comment(2)
I'll look at inclued. As far as Xdebug, it's my understanding it requires active code execution. Furthermore, it would only profile the sample code path. Both of which hinder the audit of complete code coverage.Fayre
Seems as inclued works similarly to Xdebug and therefore doesn't fit my exact need. Good tools though. Thanks.Fayre
D
0

I think PhpCodeAnalyzer is exactly what you're looking for - https://github.com/wapmorgan/PhpCodeAnalyzer It print list of all used external extensions in code base.

Dottydoty answered 28/8, 2015 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.