Skip to content

Commit

Permalink
Fixed bug squizlabs#1392 : Scope indent calculated incorrectly when u…
Browse files Browse the repository at this point in the history
…sing array destructuring
  • Loading branch information
gsherwood committed Mar 19, 2017
1 parent 6b2f215 commit 2d2fb2b
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$type = $tokens[$first]['type'];
echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
}
} else if ($tokens[$first]['code'] === T_WHITESPACE) {
$first = $phpcsFile->findNext(T_WHITESPACE, ($first + 1), null, true);
}

if (isset($tokens[$first]['scope_closer']) === true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,20 @@ $foo = foo(
}
);

function test()
{
$array = [];
foreach ($array as $data) {
[
'key1' => $var1,
'key2' => $var2,
] = $data;
foreach ($var1 as $method) {
echo $method . $var2;
}
}
}

function foo()
{
$foo = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,20 @@ $foo = foo(
}
);

function test()
{
$array = [];
foreach ($array as $data) {
[
'key1' => $var1,
'key2' => $var2,
] = $data;
foreach ($var1 as $method) {
echo $method . $var2;
}
}
}

function foo()
{
$foo = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,20 @@ $foo = foo(
}
);

function test()
{
$array = [];
foreach ($array as $data) {
[
'key1' => $var1,
'key2' => $var2,
] = $data;
foreach ($var1 as $method) {
echo $method . $var2;
}
}
}

function foo()
{
$foo = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,20 @@ $foo = foo(
}
);

function test()
{
$array = [];
foreach ($array as $data) {
[
'key1' => $var1,
'key2' => $var2,
] = $data;
foreach ($var1 as $method) {
echo $method . $var2;
}
}
}

function foo()
{
$foo = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
858 => 1,
879 => 1,
1163 => 1,
1171 => 1,
1176 => 1,
1178 => 1,
1181 => 1,
1185 => 1,
1186 => 1,
1187 => 1,
1188 => 1,
1190 => 1,
1192 => 1,
1195 => 1,
1199 => 1,
1200 => 1,
1201 => 1,
1202 => 1,
);

}//end getErrorList()
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Mark Clements for the patch
- Fixed bug #1381 : Tokenizer: derefencing incorrectly identified as short array
- Fixed bug #1387 : Squiz.ControlStructures.ControlSignature does not handle alt syntax when checking space after closing brace
- Fixed bug #1392 : Scope indent calculated incorrectly when using array destructuring
</notes>
<contents>
<dir name="/">
Expand Down

0 comments on commit 2d2fb2b

Please sign in to comment.