Skip to content

Commit

Permalink
Merge pull request #152 from PHPCSStandards/universal/disallowshortli…
Browse files Browse the repository at this point in the history
…stsyntax-bug-fix

Universal/DisallowShortListSyntax: bug fix - don't skip over nested brackets
  • Loading branch information
jrfnl committed Nov 2, 2022
2 parents 80cb0d8 + 39a1bc9 commit e0c6bd0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 0 additions & 5 deletions Universal/Sniffs/Lists/DisallowShortListSyntaxSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ public function process(File $phpcsFile, $stackPtr)

if ($openClose === false) {
// Not a short list, live coding or parse error.
if (isset($tokens[$stackPtr]['bracket_closer']) === true) {
// No need to examine nested subs of this short array/array access.
return $tokens[$stackPtr]['bracket_closer'];
}

return;
}

Expand Down
5 changes: 5 additions & 0 deletions Universal/Tests/Lists/DisallowShortListSyntaxUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ if ( true )
[ $a ] = [ 'hi' ];
return $a ?? '';

// Short list in short array.
$array = [
'key' => [$a, $b] = $args,
];

// Intentional parse error. This has to be the last test in the file.
[ $a, $b
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ if ( true )
list( $a ) = [ 'hi' ];
return $a ?? '';

// Short list in short array.
$array = [
'key' => list($a, $b) = $args,
];

// Intentional parse error. This has to be the last test in the file.
[ $a, $b
1 change: 1 addition & 0 deletions Universal/Tests/Lists/DisallowShortListSyntaxUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function getErrorList()
13 => 1,
15 => 1,
24 => 1,
29 => 1,
];
}

Expand Down

0 comments on commit e0c6bd0

Please sign in to comment.