Skip to content

PHP 8 match() expression is not counted in Generic.Metrics.CyclomaticComplexity #3472

Closed
@MarkBaker

Description

@MarkBaker

PHP8 Introduced match() as a new expression syntax, similar to a switch statement but with a rather different structure, using an arrow (=>) to separate the case from the expression that it would return. This should also be factored into the CYC calculation for the Generic.Metrics.CyclomaticComplexity sniff.

When calculating the CYC, this should be evaluated like a switch statement, with each T_MATCH_ARROW token corresponding to a case and increasing the CYC by one. There is no need to add one for the T_MATCH_DEFAULT token, because this is followed by a T_MATCH_ARROW token, and to do so would be to double-count that entry.

PR to follow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions