Closed
Description
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.