21

Looking for software that will analyze php code (i.e. all of wordpress or the thematic theme) and show me pretty pictures (perhaps a block diagram) of all the connections to help me more quickly get an understanding of where things are and what's connected to what.

Ideally, this software would run on a Mac, but I'll take anything: Windows, Linux, web-based, etc.

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
Simon
  • 480
  • 1
  • 3
  • 11
  • 7
    I think there's something fundamentally wrong about the design of blogging software that requires you to have a PHP code visualizer to understand its themes. – John Feminella Feb 23 '10 at 16:54
  • 1
    http://www.nwiresoftware.com/ comes to mind. But it is commercial. – Gordon Feb 23 '10 at 17:00
  • @John not really, but when you just start it can be hard to districate yourself from the tangle. I've wished for something like this in some projects, but then I memorized their structures myself. – Adriano Varoli Piazza Feb 23 '10 at 17:07
  • @Adriano: I guess my point is that themes for blogging software are fundamentally supposed to be easy to adapt and modify -- ease of customization is usually a major selling point. If you have to bust out a code visualizer just to get started, that tells me that whoever designed the plugin system for the blog platform didn't think things all the way through. – John Feminella Feb 23 '10 at 17:10
  • @John while I agree, the author also said he's using Wordpress aka the blog system with the codebase from hell ;) – Gordon Feb 23 '10 at 17:37
  • @Gordon: Actually, I don't think he said that anywhere, but I think it's a safe assumption on your part. – John Feminella Feb 23 '10 at 17:48
  • Hi Simon, (or others) have you found proper PHP visualizer since then? The question is still totally relevant in 2020 at least for me! I'm looking for software, tools to do this for me instead me manually drawing/mapping out (quite slowly) the complex wp plugins' architecture in some mindmapper tools and so..(it can take hours, days otherwise) Cheers for any fresh hints! – Viktor Borítás Apr 09 '20 at 13:18

6 Answers6

4

[UPDATE: This answer does not handle namespaces, so is basically obsolete. I'll leave it here in case anyone finds the DOT approach interesting.]

Here's a simple way to graph class inheritance in PHP.

Grep for class definitions and then transform the grep output to DOT syntax. NOTE: This process WILL require trial and error in your situation. Run the grep separately, and tweak it to show the right class definition lines before putting it in the script!

This script was for PHP on standard *nix (I used Ubuntu), with graphviz installed, and using grep -v to exclude some directories that were of no interest because I was looking at a CakePHP codebase. Fdp worked better than sfdp, dot, circo or neato in this situation.

Create generateClassHierarchy.sh

#!/bin/bash
echo 'digraph code {' > code.dot;
grep -r "^class " * | grep -v "^app/vendors" | grep -v "^cake/" | grep -v "Binary file" | sed 's/.*://' | sed 's/class /    /' | sed 's/ extends / -> /' | sed 's/ implements .*//'  | sed 's/ \?{.*$//' | sort >> code.dot  
echo '}' >> code.dot; 
fdp -Tpng -ocode.fdp.png code.dot 2> /dev/null # Ignore syntax error
echo "OK"; 

Then just:

cd /var/www/my_app/                     # or wherever
bash ~/shell/generateClassHierarchy.sh  # or wherever
eog code.fdp.png 

Replace eog with your preferred image viewer. I have run this on Zend Framework as a test, and produced a 22 megabyte PNG graph. Running it on just Zend_Db shows you this (example is on my site):

http://chapman.id.au/generate-php-class-inheritance-diagrams-in-graphviz

eukras
  • 869
  • 7
  • 4
  • 2
    nice one, thanks. i tweaked things by also including abstract classes. first bit becomes `egrep -r "^(abstract class|class) "`. note that you can chain further grep and grep -v things to limit what classes you want to operate on. – dbu May 21 '14 at 09:27
4
  • KCachegrind - With Xdebug you can profile the execution of your scripts, KCachegrind can generate some pretty awesome call graphs from this
  • nwire for Eclipse
hobodave
  • 28,925
  • 4
  • 72
  • 77
2

Maybe http://phpcallgraph.sourceforge.net/ for static analysis.

It can output to various formats.

Arc
  • 11,143
  • 4
  • 52
  • 75
2

BOUML can make UML diagrams out of existing PHP code

powtac
  • 40,542
  • 28
  • 115
  • 170
0

nWire is outdated, does not support latest PHP versions (namespaces). Community version of Visual Paradigm is free for non commercial projects, but fails on latest PHP versions too.

phUML is very useful free tool It's not maintained anymore, but still works fine for PHP 5. Mac users shall install graphviz too.

D.A.H
  • 858
  • 2
  • 9
  • 19
-4

Try JB Graph

if you good in java script then try D3.js

https://d3js.org/

Mohan Kumar
  • 169
  • 1
  • 9