44
55use PHP_CodeSniffer \Files \File ;
66use PHP_CodeSniffer \Util \Tokens ;
7+ use PHPCSUtils \Utils \Arrays ;
8+ use PHPCSUtils \Utils \MessageHelper ;
9+ use PHPCSUtils \Utils \TextStrings ;
710use WordPressCS \WordPress \AbstractArrayAssignmentRestrictionsSniff ;
811
912/**
@@ -104,7 +107,8 @@ protected function check_meta_query_item( int $array_open ) {
104107 $ array_open_token = $ this ->tokens [ $ array_open ];
105108 if ( $ array_open_token ['code ' ] !== T_ARRAY && $ array_open_token ['code ' ] !== T_OPEN_SHORT_ARRAY ) {
106109 // Dynamic value, we can't check.
107- $ this ->addMessage (
110+ MessageHelper::addMessage (
111+ $ this ->phpcsFile ,
108112 'meta_query is dynamic, cannot be checked. ' ,
109113 $ array_open ,
110114 'warning ' ,
@@ -114,7 +118,7 @@ protected function check_meta_query_item( int $array_open ) {
114118 return ;
115119 }
116120
117- $ array_bounds = $ this ->find_array_open_close ( $ array_open );
121+ $ array_bounds = Arrays:: getOpenClose ( $ this ->phpcsFile , $ array_open );
118122 $ elements = $ this ->get_array_indices ( $ array_bounds ['opener ' ], $ array_bounds ['closer ' ] );
119123
120124 // Is this a "first-order" query?
@@ -138,7 +142,7 @@ protected function check_meta_query_item( int $array_open ) {
138142
139143 foreach ( $ elements as $ element ) {
140144 if ( isset ( $ element ['index_start ' ] ) ) {
141- $ index = $ this -> strip_quotes ( $ this ->tokens [ $ element ['index_start ' ] ]['content ' ] );
145+ $ index = TextStrings:: stripQuotes ( $ this ->tokens [ $ element ['index_start ' ] ]['content ' ] );
142146 if ( strtolower ( $ index ) === 'relation ' ) {
143147 // Skip 'relation' element.
144148 continue ;
@@ -176,7 +180,7 @@ protected function get_static_value_for_element( array $element ) : ?string {
176180 return static ::DYNAMIC_VALUE ;
177181 }
178182
179- return $ this -> strip_quotes ( $ this ->tokens [ $ value_start ]['content ' ] );
183+ return TextStrings:: stripQuotes ( $ this ->tokens [ $ value_start ]['content ' ] );
180184 }
181185
182186 /**
@@ -208,7 +212,7 @@ protected function find_key_in_array( array $elements, string $array_key ) : ?ar
208212 continue ;
209213 }
210214
211- $ index = $ this -> strip_quotes ( $ this ->tokens [ $ start ]['content ' ] );
215+ $ index = TextStrings:: stripQuotes ( $ this ->tokens [ $ start ]['content ' ] );
212216 if ( $ index !== $ array_key ) {
213217 // Not the item we want, skip.
214218 continue ;
@@ -270,15 +274,17 @@ protected function check_compare_value( string $compare, int $stackPtr = null )
270274 }
271275
272276 if ( $ compare === static ::DYNAMIC_VALUE ) {
273- $ this ->addMessage (
277+ MessageHelper::addMessage (
278+ $ this ->phpcsFile ,
274279 'meta_query is using a dynamic comparison; this cannot be checked automatically, and may be non-performant. ' ,
275280 $ stackPtr ,
276281 'warning ' ,
277282 'dynamic_compare '
278283 );
279284 } elseif ( $ compare !== 'EXISTS ' && $ compare !== 'NOT EXISTS ' ) {
280285 // Add a message ourselves.
281- $ this ->addMessage (
286+ MessageHelper::addMessage (
287+ $ this ->phpcsFile ,
282288 'meta_query is using %s comparison, which is non-performant. ' ,
283289 $ stackPtr ,
284290 'warning ' ,
0 commit comments