@@ -382,20 +382,32 @@ public function process_token( $stackPtr ) {
382382
383383 if ( false !== $ function_opener ) {
384384
385- if ( 'array_map ' === $ functionName ) {
386-
387- // Get the first parameter (name of function being used on the array).
388- $ mapped_function = $ this ->phpcsFile ->findNext (
389- Tokens::$ emptyTokens ,
390- ( $ function_opener + 1 ),
391- $ this ->tokens [ $ function_opener ]['parenthesis_closer ' ],
392- true
385+ if ( isset ( $ this ->arrayWalkingFunctions [ $ functionName ] ) ) {
386+
387+ // Get the callback parameter.
388+ $ callback = $ this ->get_function_call_parameter (
389+ $ ptr ,
390+ $ this ->arrayWalkingFunctions [ $ functionName ]
393391 );
394392
395- // If we're able to resolve the function name, do so.
396- if ( $ mapped_function && \T_CONSTANT_ENCAPSED_STRING === $ this ->tokens [ $ mapped_function ]['code ' ] ) {
397- $ functionName = $ this ->strip_quotes ( $ this ->tokens [ $ mapped_function ]['content ' ] );
398- $ ptr = $ mapped_function ;
393+ if ( ! empty ( $ callback ) ) {
394+ /*
395+ * If this is a function callback (not a method callback array) and we're able
396+ * to resolve the function name, do so.
397+ */
398+ $ mapped_function = $ this ->phpcsFile ->findNext (
399+ Tokens::$ emptyTokens ,
400+ $ callback ['start ' ],
401+ ( $ callback ['end ' ] + 1 ),
402+ true
403+ );
404+
405+ if ( false !== $ mapped_function
406+ && \T_CONSTANT_ENCAPSED_STRING === $ this ->tokens [ $ mapped_function ]['code ' ]
407+ ) {
408+ $ functionName = $ this ->strip_quotes ( $ this ->tokens [ $ mapped_function ]['content ' ] );
409+ $ ptr = $ mapped_function ;
410+ }
399411 }
400412 }
401413
0 commit comments