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
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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) {
+10 −0
Original line number Diff line number Diff line
@@ -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];
}