Skip to content
Snippets Groups Projects
Unverified Commit b9da11fe authored by Mitch Portier's avatar Mitch Portier Committed by GitHub
Browse files

feat(VariableAnalysis): Add key support to short list unpacking (#3122608 by Arkener)

parent f9fb9a17
Branches
Tags
No related merge requests found
......@@ -1694,7 +1694,7 @@ class VariableAnalysisSniff implements Sniff
}
// Are we within a short list [...] construct?
$closePtr = $phpcsFile->findNext([T_WHITESPACE, T_VARIABLE, T_COMMA], ($stackPtr + 1), null, true);
$closePtr = $phpcsFile->findNext([T_WHITESPACE, T_VARIABLE, T_COMMA, T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_ARROW], ($stackPtr + 1), null, true);
if ($tokens[$closePtr]['code'] === T_CLOSE_SHORT_ARRAY) {
// OK, we're a short list [...] construct... are we being assigned to?
if (($assignPtr = $this->isNextThingAnAssign($phpcsFile, $closePtr)) !== false) {
......
......@@ -41,3 +41,13 @@ function test5() {
return [$a, $b, $x, $y];
}
function test6() {
$foo = ['a' => 1, 'b' => 2];
['a' => $a, 'b' => $b] = $foo;
$bar = ['x' => 3, 'y' => 4];
list('x' => $x, 'y' => $y) = $bar;
return [$a, $b, $x, $y];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment