PHP Depend - Software Metrics for PHP

WMC - Weighted Method Count

The Weighted Method Count or Weighted Method per Class metric was originally defined in A Metrics Suite for Object Oriented Design by Chidamber & Kemerer [1] .

The WMC metric is defined as the sum of complexities of all methods declared in a class. This metric is a good indicator how much effort will be necessary to maintain and develop a particular class. There are three slightly different definitions of the WMC, where each definition uses another metric as a measure of the methods' complexity. Possible complexity values are:

PHP_Depend uses the sum of Cyclomatic Complexity Numbers of all methods and constructors declared in a class to calculate the WMC metric. A lower WMC usually indicates to a class with better abstraction and polymorphism. While a class with a high complexity value is a good indicator that it this class is very application specific and does more than one job, and therefore harder to test, reuse and maintain.

Thresholds

An appropriate threshold for the WMC lower limit is 1, because a class should at least consist of one method. An upper limit for the WMC of a class is harder to define and you can find several different suggestions in the literature. But it seems that an upper limit of 50 is a good reference point for most projects that start to use the Weighted Method Count metric.

Bibliography

1
http://www.iiitd.ac.in/PhD2010/papers/SW_Paper2.pdf
IEEE Transactions on Software Engineering, A Metrics Suite for Object Oriented Design, Chidamber & Kemerer, 1994
2
http://www.literateprogramming.com/mccabe.pdf
IEEE Transactions on Software Engineering, A Complexity Measure, Thomas McCabe, 1976
Build on CloudBees button