Key is the function name. */ protected $target_functions = array( 'in_array' => array( 'param_position' => 3, 'param_name' => 'strict', 'always_needed' => true, ), 'array_search' => array( 'param_position' => 3, 'param_name' => 'strict', 'always_needed' => true, ), 'array_keys' => array( 'param_position' => 3, 'param_name' => 'strict', 'always_needed' => false, ), ); /** * Process the parameters of a matched function. * * @since 0.11.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 ) { $param_info = $this->target_functions[ $matched_content ]; /* * Check if the strict check is actually needed. * * Important! This check only applies to array_keys() in the current form of the sniff * and has been written to be specific to that function. * If more functions would be added with 'always_needed' set to `false`, * this code will need to be adjusted to handle those. */ if ( false === $param_info['always_needed'] ) { $has_filter_value = PassedParameters::getParameterFromStack( $parameters, 2, 'filter_value' ); if ( false === $has_filter_value ) { return; } } $found_parameter = PassedParameters::getParameterFromStack( $parameters, $param_info['param_position'], $param_info['param_name'] ); if ( false === $found_parameter || 'true' !== strtolower( $found_parameter['clean'] ) ) { $errorcode = 'MissingTrueStrict'; /* * Use a different error code when `false` is found to allow for excluding * the warning as this will be a conscious choice made by the dev. */ if ( is_array( $found_parameter ) && 'false' === strtolower( $found_parameter['clean'] ) ) { $errorcode = 'FoundNonStrictFalse'; } $this->phpcsFile->addWarning( 'Not using strict comparison for %s; supply true for $%s argument.', ( isset( $found_parameter['start'] ) ? $found_parameter['start'] : $stackPtr ), $errorcode, array( $matched_content, $param_info['param_name'] ) ); } } }