Skip to content

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

Closed
@MarkBaker

Description

@MarkBaker

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions