1.2.759. Nested Match

Nested match calls makes the code difficult to read. It is recommended to avoid nesting match calls.

<?php

$a = match($b) {
     1 => 3,
     3 => 'ab',
     5 => match($c) {
             6 => new X,
             7 => [],
     }
     default => false,
};

?>

1.2.759.1. Suggestions

  • Merge the two match() in one.

  • Replace the nested match call by a method call.

1.2.759.2. Specs

Short name

Structures/NestedMatch

Rulesets

All, Analyze, Changed Behavior

Exakat since

2.6.5

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud