PHP Depend - Software Metrics for PHP

NPM - Number of Public Methods

The Number of Public Methods or NPM metric was originally described in the fundamental book Object-Oriented Software Metrics of Lorenz and Kidd [1] .

The NPM metric The NPM metric belongs to the group of simple count software metrics. This means that this value simply reflects the number of public methods declared in a class.

A high NPM value can be an indicator for two different bad smells in the design of a software. First it can be a signal for a class that is to complex and has too many responsibilities in the analyzed software system. This can be verified by looking at Weighted Method per Class metric for the same class. A good example for such a subject is the well known utility class with all those methods, which are used all over the software system.

Secondly a high NPM value can be an indicator for a class that is highly coupled with other parts of the software, because every public method may expose the internally used classes. Or the class acts as some kind of context, to transfer objects between several components. This can be verified for possible candidates, by looking at the coupling metrics for the same class, for example the Coupling Between Objects and the Afferent Coupling metric.


An appropriate threshold for the NPM lower limit is 1, because a class should at least define a single method that can be utilized by the application. An upper limit for the NPM metric of a class is harder to define, because it depends on the type of the class, is it a simple DTO (Data Transfer Object) with several getter and setter methods or is it a Domain Object that defines a single well defined service in the analyzed application.


Prentice Hall; Object-Oriented Software Metrics; Mark Lorenz, Jeff Kidd; 1994; ISBN: 9780131792920
Build on CloudBees button