Installing PHP_Depend
I found an article about creating packages and to improve the modularity of your code. I’ve been always wondering the meaning for packages, but haven’t found any good explanation before stumbling on jDepend (PHP_Depend). This seems to be great stuff for honing your object architecture design skills!
What the jDepend/PHP_Depend tries to say is, instead of putting all classes into one package, or making a separate package for exceptions etc, you should try to think packages as modules. JDepend and PHP_Depend helps you to check how modular your code really is. Read more here.
INSTALLATION
Login as root and type
pear channel-discover pear.pdepend.org
pear install pdepend/PHP_Depend-beta
Then go to your source code directory and run
pdepend –summary-xml=/tmp/summary.xml –jdepend-chart=/tmp/jdepend.svg –overview-pyramid=/tmp/pyramid.svg .
Then go to /tmp with your web-browser and you should see two graphs. The pyramid shows suggestions and ratios for example of the NOP (Number of Packages) and NOC (Nubmer of Classes). According to one scientific article you should have an avarage of 17 classes in a package. If you have less than 6 or more than 27, then you should perhaps consider refactoring your code. See all the explanations from here.
The second graphs shows the (perpendicular) distance of packages from the idealized line A + I = 1. This metric is an indicator of the package’s balance between abstractness (A) and instability (I). A package squarely on the main sequence is optimally balanced with respect to its abstractness and stability. Ideal packages are either completely abstract and stable (x=0, y=1) or completely concrete and instable (x=1, y=0). The range for this metric is 0 to 1, with D=0 indicating a package that is coincident with the main sequence and D=1 indicating a package that is as far from the main sequence as possible.
Here are the explanations:
- Abstractness The ratio of the number of abstract classes (and interfaces) in the analyzed package to the total number of classes in the analyzed package. The range for this metric is 0 to 1, with A=0 indicating a completely concrete package and A=1 indicating a completely abstract package.
- Instability The ratio of efferent coupling (Ce) to total coupling (Ce / (Ce + Ca)). This metric is an indicator of the package’s resilience to change. The range for this metric is 0 to 1, with I=0 indicating a completely stable package and I=1 indicating a completely instable package.
- Efferent Couplings The number of other packages that the classes in the package depend upon is an indicator of the package’s independence.
- Afferent Couplings The number of other packages that depend upon classes within the package is an indicator of the package’s responsibility.