
In one of the reviews on Habré, the PHP Depend code analyzer (
http://pdepend.org/ ) was already mentioned. In this material I would like to consider a small example of its use and interpretation of results.
Installation
Let's start from the beginning - with the installation. PHP Depend requires PEAR.
Register the pdepend channel to pear:
94:bin sergeypanarin$ ./pear channel-discover pear.pdepend.org
Adding Channel "pear.pdepend.org" succeeded
Discovery of channel "pear.pdepend.org" succeeded
Install:
94:bin sergeypanarin$ ./pear install pdepend/PHP_Depend-beta
Did not download optional dependencies: pecl/imagick, use --alldeps to download automatically
pdepend/PHP_Depend can optionally use package "pecl/imagick" (version >= 2.2.0b2)
downloading PHP_Depend-0.9.9.tgz ...
Starting to download PHP_Depend-0.9.9.tgz (291,705 bytes)
.............................................................done: 291,705 bytes
install ok: channel://pear.pdepend.org/PHP_Depend-0.9.9
')
Check the installation is correct:
94:bin sergeypanarin$ ./pdepend --version
PHP_Depend 0.9.9 by Manuel Pichler
We start the test run on the source code of the analyzer itself:
94:bin sergeypanarin$ ./pdepend --summary-xml=/Users/sergeypanarin/PDepend/summary.xml --jdepend-chart=/Users/sergeypanarin/PDepend/jdepend.svg --overview-pyramid=/Users/sergeypanarin/PDepend/pyramid.svg /Users/sergeypanarin/PEAR/PEAR/PHP/Depend
PHP_Depend 0.9.9 by Manuel Pichler
Parsing source files:
............................................................ 60
............................................................ 120
................................. 153
Executing CyclomaticComplexity-Analyzer:
............................................................ 1200
...... 1335
Executing ClassLevel-Analyzer:
............................................................ 1200
1204
Executing CodeRank-Analyzer:
........ 180
Executing Coupling-Analyzer:
............................................................ 1200
................. 1545
Executing Dependency-Analyzer:
......................................................... 1160
Executing Hierarchy-Analyzer:
............................................................ 1200
........ 1370
Executing Inheritance-Analyzer:
...................... 443
Executing NodeCount-Analyzer:
........................................................ 1123
Executing NodeLoc-Analyzer:
............................................................ 1200
... 1276
Executing NPathComplexity-Analyzer:
............................................................ 1200
...... 1335
Generating pdepend log files, this may take a moment.
Time: 00:27; Memory: 48.00Mb
The resulting files can be downloaded from here -
results_0.zipInterpretation of results
The results include 3 files:
- summary.xml - full source code analysis results
- jdepend.svg
- pyramid.svg
We’ll dwell on the last two files.
jdepend.svg

Each of the “balls” displays the files of a specific package-folder (in the svg-file, when you hover over the ball, a hint with the name of the package pops up). The size of the ball is determined by the number of abstract and specific classes in the package.
On the x-axis, the abstraction ratio values are plotted, on the y-axis,
the instability ratio.
The straight line represents the optimal ratio between these coefficients.
The abstraction ratio (A) is the ratio of the number of abstract classes and interfaces to the total number of classes in the package being analyzed. Accepts a value from 0 to 1. If it is 0, then the packet is absolutely specific, if 1 is absolutely abstract.
The centripetal connectedness coefficient (afferent couplings, Ca) is the number of packets that depend on the classes of the current packet.
The centrifugal connectivity coefficient (efferent couplings, Ce) is the number of packages on which the classes of the current package depend.
The instability ratio (I) is the ratio of the centrifugal connectivity coefficient to the sum of the coupling coefficients: I = Ce / (Ce + Ca). Shows package resilience to change. Accepts a value from 0 to 1. If it is 0, it is considered an absolutely stable package (does not depend at all on other packages), if 1 - then absolutely unstable (completely dependent package, on which others do not depend).
pyramid.svg

The data is displayed in the form of a pyramid, because the coefficients obtained as the ratio of the characteristic values from the level below and the current level are located on its outer edges. The values of the coefficients "tinted" depending on whether it falls into a range of values - low, medium and high.
That is, for example, 0.176 = CYCLO / LOC.
Now more about the abbreviations used.
Left:
CYCLO (Cyclomatic Complexity) - cyclomatic complexity of packages (based on the number of branches in a code like if, for, foreach).
LOC (Lines Of Code) - the number of lines of code.
NOM (Number Of Methods + functions) - the number of class methods + the number of functions.
NOC (Number Of Classes) - the number of classes.
NOP (Number Of Packages) - the number of packets.
AHH (Average Hierarchy Height) - the average depth of the hierarchy.
AND (Average Number of Derived classes) is the average number of descendant classes.
On right:
FANOUT (Number of Called Classes) is the number of classes used (presumably, the number of class objects created).
CALLS (Number of Operation Calls) - the number of calls to methods and functions.
PS Happy New Year to all and Merry Christmas!