>> Key is function name, value is * an array containing information * about the name and position of * the relevant parameters. */ protected $target_functions = array( 'get_comment_meta' => array( 'condition' => array( 'param_name' => 'key', 'position' => 2, ), 'recommended' => array( 'param_name' => 'single', 'position' => 3, ), ), 'get_metadata' => array( 'condition' => array( 'param_name' => 'meta_key', 'position' => 3, ), 'recommended' => array( 'param_name' => 'single', 'position' => 4, ), ), 'get_metadata_default' => array( 'condition' => array( 'param_name' => 'meta_key', 'position' => 3, ), 'recommended' => array( 'param_name' => 'single', 'position' => 4, ), ), 'get_metadata_raw' => array( 'condition' => array( 'param_name' => 'meta_key', 'position' => 3, ), 'recommended' => array( 'param_name' => 'single', 'position' => 4, ), ), 'get_post_meta' => array( 'condition' => array( 'param_name' => 'key', 'position' => 2, ), 'recommended' => array( 'param_name' => 'single', 'position' => 3, ), ), 'get_site_meta' => array( 'condition' => array( 'param_name' => 'key', 'position' => 2, ), 'recommended' => array( 'param_name' => 'single', 'position' => 3, ), ), 'get_term_meta' => array( 'condition' => array( 'param_name' => 'key', 'position' => 2, ), 'recommended' => array( 'param_name' => 'single', 'position' => 3, ), ), 'get_user_meta' => array( 'condition' => array( 'param_name' => 'key', 'position' => 2, ), 'recommended' => array( 'param_name' => 'single', 'position' => 3, ), ), ); /** * Process the parameters of a matched function. * * @since 3.2.0 * * @param int $stackPtr The position of the current token in the stack. * @param string $group_name The name of the group which was matched. * @param string $matched_content The token content (function name) which was matched * in lowercase. * @param array $parameters Array with information about the parameters. * * @return void */ public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) { $condition = $this->target_functions[ $matched_content ]['condition']; $recommended = $this->target_functions[ $matched_content ]['recommended']; $meta_key = PassedParameters::getParameterFromStack( $parameters, $condition['position'], $condition['param_name'] ); if ( ! is_array( $meta_key ) ) { return; } $single = PassedParameters::getParameterFromStack( $parameters, $recommended['position'], $recommended['param_name'] ); if ( is_array( $single ) ) { $this->phpcsFile->recordMetric( $stackPtr, self::METRIC_NAME, 'yes' ); return; } $this->phpcsFile->recordMetric( $stackPtr, self::METRIC_NAME, 'no' ); $tokens = $this->phpcsFile->getTokens(); $message_data = array( $condition['param_name'], $tokens[ $stackPtr ]['content'], $recommended['param_name'], ); $this->phpcsFile->addWarning( 'When passing the $%s parameter to %s(), it is recommended to also pass the $%s parameter to explicitly indicate whether a single value or multiple values are expected to be returned.', $stackPtr, 'Missing', $message_data ); } }