How to understand the PhpMetrics' metrics

According to me, you should understand at least the following metrics at beginning:

Lack of cohesion of methods


Lack of cohesion of methods (LCOM) is a measure of the number of responsabilities of class.

Thus, if you consider the SOLID principles, the ideal LCOM is LCOM=1.

We can take an example:

<?php
class Example {
    private $a;
    private $b;
    public function f1() {
        $this->a = 1;
    }
    public function f2() {
        $this->f3();
    }
    public function f3() {
        $this->a = 2;
    }
    public function f4() {
        $this->b = 3;
    }
    public function f5() {
        $this->b = 4;
    }
}

If we examine this class, we get two flows:

  • f1() share attribute a with f3(), and f2() calls f3()
  • f4() share attribute b with f5()

Therefore, the LCOM value for Example is 2. Indeed, Example has two responsabilities.

Maintainability Index


Maintainability index evaluates ... the maintainability of any project. It provides a score between 0 to 118.

This score is standard, and works for any language : PHP, .Net, Java...

Generally, we consider the following scores:

  • <64: low maintainability. The project has probably technical debt.
  • 65-84: medium maintainability. The project has problems, but nothing really serious.
  • >85: high maintainability. The project is probably good.

Halstead' difficulty


Soon