I'm testing my libraries with pdepend and some functions have incredibly high complexity. I just realized it comes from the ternary operator, but I'm not sure why.
With a function like:
function test($a) {
return $a > 10 ? 5:20;
}
pdepend returns a complexity (npath) of 5. Why 5 different paths? I see only 2.
With a function like:
function test($a) {
if($a > 10)
return 5;
else
return 20;
}
The npath complexity is 2. Which makes sense.
Edit: Ok I had a look at the other question: PMD - NPath complexity very high with ternary operator (?
It's part of the algorithm.. Still, the function has only 2 possible paths. The algorithm doesn't make sense to me. The number of nodes do not reflect the number of paths, and it arbitrarily adds 2 to the value.