Closed
Description
Hi,
I've noticed PhpMetrics does not correctly report cyclomatic complexity and max method cyclomatic complexity.
The bug is due to CyclomaticComplexityVisitor::leaveNode(), line 61 not taking into account else branches, elseif branches and ternary operators in control statement conditions.
if (isset($node->stmts) && $node->stmts) {
foreach ($node->stmts as $child) {
$ccn += $cb($child);
}
}
Here's an example:
Say the $cb
function is analysing an if
statement. All nodes in the $node->stmts
will be evaluated, but these are only the statements in the true
branch. Thus, the else
branch and elseif
branches are ignored.
I will make a PR with a fix shortly. Here.
Metadata
Metadata
Assignees
Labels
No labels