Skip to content

Commit

Permalink
Merge pull request #34 from PHPCSStandards/feature/universal-mixedkey…
Browse files Browse the repository at this point in the history
…edunkeyedarray-add-extra-unit-test

Universal/MixedKeyedUnkeyedArray: improve defensive coding
  • Loading branch information
jrfnl committed Feb 18, 2020
2 parents 42d0b67 + 7e52d2f commit d931865
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Universal/Sniffs/Arrays/MixedKeyedUnkeyedArraySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public function processKey(File $phpcsFile, $startPtr, $endPtr, $itemNr)
public function processNoKey(File $phpcsFile, $startPtr, $itemNr)
{
$firstNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $startPtr, null, true);
if ($firstNonEmpty === false) {
// Shouldn't be possible.
if ($firstNonEmpty === false || $this->tokens[$firstNonEmpty]['code'] === \T_COMMA) {
// Shouldn't really be possible, but this must be a parse error (empty array item).
return;
}

Expand Down
6 changes: 6 additions & 0 deletions Universal/Tests/Arrays/MixedKeyedUnkeyedArrayUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ $array = [
'string' => 'string key',
'value',
];

// Test handling of empty array item.
$array = [
'value', /*comment*/,
'another value',
];

0 comments on commit d931865

Please sign in to comment.