From 297acb877242131d7579800a4cc69b0c0e9ff61c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 1 Jul 2018 03:36:44 +0200 Subject: [PATCH] PreparedSQL: make the sniff more code style independent Includes unit test. --- WordPress/Sniffs/DB/PreparedSQLSniff.php | 5 ++--- WordPress/Tests/DB/PreparedSQLUnitTest.inc | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) 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