@@ -44,7 +44,8 @@ public function process_token( $stackPtr ) {
4444 // We are interested in add_action calls only.
4545 return ;
4646 }
47-
47+ // Should use WPCS FunctionParam abstract
48+ // Or at the very least PassedParameters class
4849 $ actionNamePtr = $ this ->phpcsFile ->findNext (
4950 array_merge ( Tokens::$ emptyTokens , [ T_OPEN_PARENTHESIS ] ),
5051 $ stackPtr + 1 ,
@@ -59,6 +60,7 @@ public function process_token( $stackPtr ) {
5960 return ;
6061 }
6162
63+ // Use TextStrings::stripQuotes()
6264 if ( substr ( $ this ->tokens [ $ actionNamePtr ]['content ' ], 1 , -1 ) !== 'pre_get_posts ' ) {
6365 // This is not setting a callback for pre_get_posts action.
6466 return ;
@@ -85,6 +87,7 @@ public function process_token( $stackPtr ) {
8587 ) {
8688 $ this ->processArray ( $ callbackPtr );
8789 } elseif ( in_array ( $ this ->tokens [ $ callbackPtr ]['code ' ], Tokens::$ stringTokens , true ) === true ) {
90+ // This can now be a first class callable
8891 $ this ->processString ( $ callbackPtr );
8992 }
9093 }
@@ -122,6 +125,7 @@ private function processArray( $stackPtr ) {
122125 */
123126 private function processString ( $ stackPtr ) {
124127
128+ // Use TextStrings::stripQuotes()
125129 $ callbackFunctionName = substr ( $ this ->tokens [ $ stackPtr ]['content ' ], 1 , -1 );
126130
127131 $ callbackFunctionPtr = $ this ->phpcsFile ->findNext (
@@ -149,6 +153,7 @@ private function processString( $stackPtr ) {
149153 */
150154 private function processFunction ( $ stackPtr ) {
151155
156+ // Should use FunctionDeclarations::getParameters()
152157 $ wpQueryObjectNamePtr = $ this ->phpcsFile ->findNext (
153158 [ T_VARIABLE ],
154159 $ stackPtr + 1 ,
@@ -166,7 +171,8 @@ private function processFunction( $stackPtr ) {
166171 $ wpQueryObjectVariableName = $ this ->tokens [ $ wpQueryObjectNamePtr ]['content ' ];
167172
168173 $ functionDefinitionPtr = $ this ->phpcsFile ->findPrevious ( [ T_FUNCTION ], $ wpQueryObjectNamePtr - 1 );
169-
174+ // Doesn't check the function name, presumes the function is declared directly above. This will be wrong in so many cases.
175+ // Test on line 112 is typical example of where things go wrong.
170176 if ( ! $ functionDefinitionPtr ) {
171177 // Something is wrong.
172178 return ;
@@ -184,6 +190,7 @@ private function processFunction( $stackPtr ) {
184190 */
185191 private function processClosure ( $ stackPtr ) {
186192
193+ // Should use FunctionDeclarations::getParameters()
187194 $ wpQueryObjectNamePtr = $ this ->phpcsFile ->findNext (
188195 [ T_VARIABLE ],
189196 $ stackPtr + 1 ,
@@ -195,6 +202,7 @@ private function processClosure( $stackPtr ) {
195202
196203 if ( ! $ wpQueryObjectNamePtr ) {
197204 // Something is wrong.
205+ // Should this possibly check if the global $wp_query variable is being imported via a closure `use` ?
198206 return ;
199207 }
200208
@@ -255,6 +263,7 @@ private function addPreGetPostsWarning( $stackPtr ) {
255263 $ this ->phpcsFile ->addWarning ( $ message , $ stackPtr , 'PreGetPosts ' );
256264 }
257265
266+ // Below functions should probably all use Conditions and Parentheses classes.
258267 /**
259268 * Is parent conditional checking is_main_query?
260269 *
0 commit comments