Skip to content

cyclomatic complexity of ternary/null coalescing in control structures #3501

Open
@mmarton

Description

@mmarton

Describe the bug

This might not be a bug, I'm just curious of your opinion

After #3469 multiple part of my code is reporting too much cyclomatic complexity.
i have something similar:

if (($variable1ThatCanBeNullOrFloat ?? 0.0) !== 0.0) {
   $context->addViolation('description');
}

if (($variable2ThatCanBeNullOrFloat ?? 0.0) !== 0.0) {
   $context->addViolation('description2');
}
// 6 more time

Until now one of this statements was +1 to complexity, not it's +2 because the null coalescing. But it's still 2 options here. stepping into the if or stepping it over.

Yes I can rewrite it to
if ($variable1ThatCanBeNullOrFloat !== null && $variable1ThatCanBeNullOrFloat !== 0.0) but it's a lot more character and I like to spare my keyboard.

what do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions