Skip to content

Commit

Permalink
Use valid closure in test; allow closures in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Oct 6, 2013
1 parent 36af35e commit 3c50375
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
*/

// Check each line ends in a comma.
if ($tokens[$index['value']]['code'] !== T_ARRAY) {
if ( ! in_array( $tokens[$index['value']]['code'], array( T_ARRAY, T_CLOSURE ) ) ) {
$nextComma = $phpcsFile->findNext(array(T_COMMA, T_OPEN_PARENTHESIS), ($index['value'] + 1));
if (($nextComma === false) || ($tokens[$nextComma]['line'] !== $tokens[$index['value']]['line'])) {
$error = 'Each line in an array declaration must end in a comma';
Expand Down
14 changes: 8 additions & 6 deletions Tests/Arrays/ArrayDeclarationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ $query_vars = array_merge(
'post_status' => 'private',
'orderby' => 'title', // Good
),
foo() { // Good, Enclosures allowed
return array();
},
bar( // Good, Functions allowed
$bar,
$taz
array(
'closure' => function () { // Good, Closures allowed
return array();
},
),
bar( // Good, Functions allowed
1,
2
)
);
$query = new WP_Query( $query_vars );

Expand Down
2 changes: 1 addition & 1 deletion Tests/Arrays/ArrayDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getErrorList()
7 => 1,
9 => 1,
16 => 1,
38 => 2,
40 => 2,
);

}//end getErrorList()
Expand Down

0 comments on commit 3c50375

Please sign in to comment.