*/ private static $arrayWalkingFunctions = array( 'array_map' => array( 'position' => 1, 'name' => 'callback', ), 'map_deep' => array( 'position' => 2, 'name' => 'callback', ), ); /** * Retrieve a list of the supported "array walking" functions. * * @since 3.0.0 * * @return array */ public static function get_functions() { return \array_fill_keys( \array_keys( self::$arrayWalkingFunctions ), true ); } /** * Check if a particular function is an "array walking" function. * * @since 3.0.0 * * @param string $functionName The name of the function to check. * * @return bool */ public static function is_array_walking_function( $functionName ) { return isset( self::$arrayWalkingFunctions[ strtolower( $functionName ) ] ); } /** * Retrieve the parameter information for the callback parameter for an array walking function. * * @since 3.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. * @param int $stackPtr The position of function call name token. * * @return array|false Array with information on the callback parameter. * Or `FALSE` if the parameter is not found. * See the PHPCSUtils PassedParameters::getParameters() documentation * for the format of the returned (single-dimensional) array. */ public static function get_callback_parameter( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); if ( isset( $tokens[ $stackPtr ] ) === false ) { return false; } $functionName = strtolower( $tokens[ $stackPtr ]['content'] ); if ( isset( self::$arrayWalkingFunctions[ $functionName ] ) === false ) { return false; } return PassedParameters::getParameter( $phpcsFile, $stackPtr, self::$arrayWalkingFunctions[ $functionName ]['position'], self::$arrayWalkingFunctions[ $functionName ]['name'] ); } }