Permalink
Browse files

Fixed bug #20026 : Check for multi-line arrays that should be single-…

…line is slightly wrong
  • Loading branch information...
1 parent b2e8039 commit cdbf8faa5b8a65e7f371d820ad2759d51d20ad2f @gsherwood gsherwood committed Aug 8, 2013
@@ -98,8 +98,17 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
if ($tokens[$i]['code'] === T_COMMA) {
- $valueCount++;
- $commas[] = $i;
+ // Before counting this comma, make sure we are not
+ // 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');
+ }
}
}
@@ -185,4 +185,7 @@ $test = array(
$value2
),
);
+
+$c = array('a' => 1,);
+
?>
@@ -93,6 +93,7 @@ public function getErrorList()
157 => 1,
174 => 3,
179 => 1,
+ 189 => 1,
);
}//end getErrorList()
View
@@ -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>
<notes>
- 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
</notes>
<contents>

0 comments on commit cdbf8fa

Please sign in to comment.