diff --git a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php index 349995eaf7..b627becf34 100644 --- a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php +++ b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php @@ -164,6 +164,15 @@ public function process_token( $stackPtr ) { $key = $this->strip_quotes( $this->tokens[ $keyIdx ]['content'] ); $valStart = $this->phpcsFile->findNext( array( T_WHITESPACE ), ( $operator + 1 ), null, true ); $valEnd = $this->phpcsFile->findNext( array( T_COMMA, T_SEMICOLON ), ( $valStart + 1 ), null, false, null, true ); + + // Step back to the actual value. + $anyValidValue = array( T_DOUBLE_QUOTED_STRING, T_CONSTANT_ENCAPSED_STRING, T_LNUMBER, T_TRUE, T_FALSE, T_CONST ); + $valTrimmedEnd = $this->phpcsFile->findPrevious( $anyValidValue, $valEnd - 1, $valStart, false, null, false ); + + if ( false !== $valTrimmedEnd ) { + $valEnd = $valTrimmedEnd + 1; + } + $val = $this->phpcsFile->getTokensAsString( $valStart, ( $valEnd - $valStart ) ); $val = $this->strip_quotes( $val ); $inst[ $key ][] = array( $val, $token['line'] ); diff --git a/WordPress/Tests/VIP/PostsPerPageUnitTest.inc b/WordPress/Tests/VIP/PostsPerPageUnitTest.inc index b22390709d..7bb9e2afca 100644 --- a/WordPress/Tests/VIP/PostsPerPageUnitTest.inc +++ b/WordPress/Tests/VIP/PostsPerPageUnitTest.inc @@ -22,3 +22,10 @@ $query_args['my_posts_per_page'] = -1; // OK. // @codingStandardsChangeSetting WordPress.VIP.PostsPerPage posts_per_page 50 $query_args['posts_per_page'] = 50; // OK. // @codingStandardsChangeSetting WordPress.VIP.PostsPerPage posts_per_page 100 + +$args = array( 'posts_per_page' => -1 ); // Bad +$args = array( 'posts_per_page' => '-1' ); // Bad +$args = array( + 'foobar' => 'doobar', + 'posts_per_page' => -1 // With a comment // Bad +); \ No newline at end of file diff --git a/WordPress/Tests/VIP/PostsPerPageUnitTest.php b/WordPress/Tests/VIP/PostsPerPageUnitTest.php index 548bf885fe..c51344f5f2 100644 --- a/WordPress/Tests/VIP/PostsPerPageUnitTest.php +++ b/WordPress/Tests/VIP/PostsPerPageUnitTest.php @@ -37,6 +37,9 @@ public function getErrorList() { 13 => 1, 16 => 1, 17 => 1, + 26 => 1, + 27 => 1, + 30 => 1, ); }