MultiAssignmentUsage
info on by defaultGroup: Control flow · PhpStorm name: MultiAssignmentUsageInspection
Two patterns where destructuring would be clearer:
- unpacking the
foreachvalue variable withlist(...) = $valueas a separate statement, whenforeach (... as list(...))can do it directly (PHP 5.5+); - consecutive statements pulling numbered elements out of the same array one at a time (
$a = $row[0]; $b = $row[1];), which a singlelist(...) = $rowreplaces.
Example
php
<?php
foreach ($pairs as $idx => $pair) {
[$left, $right] = $pair;
if (is_array($pair)) {
[$top, $bottom] = $pair; // E2b: nested under a guard
}
list($m, $n) = $other; // E2: not a loop variable
$fn = function () use ($pair) { list($u) = $pair; }; // E2: closure boundary
$width = $pair[0];
// a plain comment
/** @var int $height */
$height = $pair[1];
$depth = $pair[-1];
$name = $pair['name'];
$kind = $pair['kind']; // E4
$copy = [];
$copy[0] = $pair[1];
$copy[1] = $pair[0]; // E5
}Reported:
- line 3: Destructure directly in the foreach header.
- line 13: Use one destructuring assignment from '$pair' instead.
- line 14: Use one destructuring assignment from '$pair' instead.
Configure
In custos.json:
json
{
"rules": {
"MultiAssignmentUsage": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore MultiAssignmentUsage
/**
* @noinspection MultiAssignmentUsageInspection
*/