Maintainability Index
toniorganizer opened this issue · comments
How to get Halstead Volume value on phpmetrics latest display version? I have difficulty determining MI, because in the formula for determining MI there must be a Halstead Volume value
or have several ways to find out the value of maintainability index?
The Halstead volume metric can be found in the "Size & Volume" panel. It's on the "Volume" metric.
The value of the maintainability index can effectively be determined by several formulas. As the original formula gives values on a range that contains INF (infinite number), PhpMetrics uses a scaled ratio that is mainly used by other metric tools.
PhpMetrics also provide the MIwoC, the maintainability index without comments, as when your project has too much comments, even when they're irrelevant, it impacts too hardly the MI giving biaised results.
In every formula used, the Halstead volume metric is used as a variable.
It’s the value of the volume of code according to Halstead’s formula.
The formula is :
V = (N1 + N2) * log2(n1 + n2)
where :
- N1 is the total number of operators (not only mathematical, but also logical)
- N2 is the total number of operands
- n1 is the number of distinct operators
- n2 is the number of distinct operands
For each class, PhpMetrics calculates the volume of code regarding the Halstead’s formula.
On project view, the Halstead’s volume is the average of all classes’ volumes.
Halstead’s volume is not only used in MI calculation, but also for Halstead’s formula about « estimated number of bugs delivered », which is (sort of) B = V / 3000. You want B the lowest as possible, which means you also want V the lowest as possible. And that makes sense: the less number of operators and operands your source code has, the less probability of bugs happen.
OK, thanks for your explanation, this is very helpful.