diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index c328e84b6f..53be35b3b8 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -180,10 +180,9 @@ function ( $symbol ) { ) { // Find the opening parenthesis. - $opening_paren = $this->phpcsFile->findNext( T_WHITESPACE, ( $this->i + 1 ), null, true, null, true ); + $opening_paren = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $this->i + 1 ), null, true, null, true ); - if ( - $opening_paren + if ( false !== $opening_paren && T_OPEN_PARENTHESIS === $this->tokens[ $opening_paren ]['code'] && isset( $this->tokens[ $opening_paren ]['parenthesis_closer'] ) ) { diff --git a/WordPress/Tests/DB/PreparedSQLUnitTest.inc b/WordPress/Tests/DB/PreparedSQLUnitTest.inc index 86ae5bd2b5..57fc2c5918 100644 --- a/WordPress/Tests/DB/PreparedSQLUnitTest.inc +++ b/WordPress/Tests/DB/PreparedSQLUnitTest.inc @@ -106,5 +106,13 @@ $wpdb->query( "SELECT * FROM $wpdb->posts WHERE ID = " . (int) $foo . ";" ); // $wpdb->query( "SELECT * FROM $wpdb->posts WHERE value = " . (float) $foo . ";" ); // Ok. +$wpdb->query( + "SELECT * FROM $wpdb->posts + WHERE ID = " + . absint // Ok. + ( $foo ) + . ";" +); + // Don't throw an error during live coding. wpdb::prepare( "SELECT * FROM $wpdb->posts