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

The nullsafe operator is not counted in Generic.Metrics.CyclomaticComplexity #3505

Closed
MarkBaker opened this issue Dec 17, 2021 · 1 comment
Closed
Milestone

Comments

@MarkBaker
Copy link
Contributor

As highlighted in discussion of Issue #3501, the NullSafe Operator (?->) is not taken into consideration when calculating complexity in the Generic.Metrics.CyclomaticComplexity sniff.

This operator should increment the Cyclomatic Complexity score by 1, because there are two paths through the code each cases.

$result = $object->getX()?->getY();

can be re-written as an if/else statement

if ($object->getX() !== null) {
    $result = $object->getX()->getY();
} else {
    $result = null;
}

with two branches through the code, which should increment the CYC count by one.

@gsherwood gsherwood added this to the 3.7.0 milestone Dec 19, 2021
@gsherwood gsherwood changed the title The nullsafe operator (?->) is not counted in Generic.Metrics.CyclomaticComplexity The nullsafe operator is not counted in Generic.Metrics.CyclomaticComplexity Jan 17, 2022
gsherwood added a commit that referenced this issue Jan 17, 2022
@gsherwood
Copy link
Member

Fixed by attached PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants