Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cyclomatic Complexity not reported correctly #343

Closed
fabianbadoi opened this issue Apr 5, 2018 · 0 comments
Closed

Cyclomatic Complexity not reported correctly #343

fabianbadoi opened this issue Apr 5, 2018 · 0 comments

Comments

@fabianbadoi
Copy link
Contributor

fabianbadoi commented Apr 5, 2018

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.

UFOMelkor added a commit that referenced this issue May 24, 2018
Fix issue #343 (Cyclomatic Complexity not reported correctly)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant