ValidationHelper
in package
Helper function for checking whether a token is validated.
Tags
Table of Contents
Properties
- $key_exists_functions : array<string, bool>
- List of PHP native functions to check if an array index exists.
- $targets : array<int|string, string>
- The tokens the function looks for to determine whether a token is validated.
Methods
- is_validated() : bool
- Check if the existence of a variable is validated with isset(), empty(), array_key_exists() or key_exists().
- strip_quotes_from_array_values() : array<string|int, string>
- Strip quotes of all the values in an array containing only text strings.
Properties
$key_exists_functions
List of PHP native functions to check if an array index exists.
private
static array<string, bool>
$key_exists_functions
= array('array_key_exists' => true, 'key_exists' => true)
Tags
$targets
The tokens the function looks for to determine whether a token is validated.
private
static array<int|string, string>
$targets
= array(\T_ISSET => 'construct', \T_EMPTY => 'construct', \T_STRING => 'function_call', \T_COALESCE => 'coalesce', \T_COALESCE_EQUAL => 'coalesce')
Tags
Methods
is_validated()
Check if the existence of a variable is validated with isset(), empty(), array_key_exists() or key_exists().
public
static is_validated(File $phpcsFile, int $stackPtr[, array<string|int, mixed>|string $array_keys = array() ][, bool $in_condition_only = false ]) : bool
When $in_condition_only is false, (which is the default), this is considered
valid:
if ( isset( $var ) ) {
// Do stuff, like maybe return or exit (but could be anything)
}
foo( $var );
When it is true, that would be invalid; the use of the variable must be within
the scope of the validating condition, like this:
if ( isset( $var ) ) {
foo( $var );
}
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The index of this token in the stack.
- $array_keys : array<string|int, mixed>|string = array()
-
An array key to check for ("bar" in $foo['bar']) or an array of keys for multi-level array access.
- $in_condition_only : bool = false
-
Whether to require that this use of the variable occurs within the scope of the validating condition, or just in the same scope (default).
Tags
Return values
bool —Whether the var is validated.
strip_quotes_from_array_values()
Strip quotes of all the values in an array containing only text strings.
private
static strip_quotes_from_array_values(array<string|int, string> $text_strings) : array<string|int, string>
Parameters
- $text_strings : array<string|int, string>
-
The input array.