Skip to content

Commit

Permalink
Fixed bug #20026 : Check for multi-line arrays that should be single-…
Browse files Browse the repository at this point in the history
…line is slightly wrong
  • Loading branch information
gsherwood committed Aug 8, 2013
1 parent b2e8039 commit cdbf8fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Expand Up @@ -98,8 +98,17 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
} }


if ($tokens[$i]['code'] === T_COMMA) { if ($tokens[$i]['code'] === T_COMMA) {
$valueCount++; // Before counting this comma, make sure we are not
$commas[] = $i; // at the end of the array.
$next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), $arrayEnd, TRUE);
if ($next !== false) {
$valueCount++;
$commas[] = $i;
} else {
// There is a comma at the end of a single line array.
$error = 'Comma not allowed after last value in single-line array declaration';
$phpcsFile->addError($error, $i, 'CommaAfterLast');
}
} }
} }


Expand Down
Expand Up @@ -185,4 +185,7 @@ $test = array(
$value2 $value2
), ),
); );

$c = array('a' => 1,);

?> ?>
Expand Up @@ -93,6 +93,7 @@ public function getErrorList()
157 => 1, 157 => 1,
174 => 3, 174 => 3,
179 => 1, 179 => 1,
189 => 1,
); );


}//end getErrorList() }//end getErrorList()
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Expand Up @@ -27,6 +27,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license> <license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
<notes> <notes>
- Added support for the PHP 5.4 callable type hint - Added support for the PHP 5.4 callable type hint
- Fixed bug #20026 : Check for multi-line arrays that should be single-line is slightly wrong
-- Adds new error message for single-line arrays that end with a comma
- Fixed bug #20029 : ForbiddenFunction sniff incorrectly recognizes methods in USE clauses - Fixed bug #20029 : ForbiddenFunction sniff incorrectly recognizes methods in USE clauses
</notes> </notes>
<contents> <contents>
Expand Down

0 comments on commit cdbf8fa

Please sign in to comment.