Conditions
in package
Utility functions for use when examining token conditions.
Tags
Table of Contents
Methods
- getCondition() : int|false
- Retrieve the position of a condition for the passed token.
- getFirstCondition() : int|false
- Return the position of the first (outermost) condition of a certain type for the passed token.
- getLastCondition() : int|false
- Return the position of the last (innermost) condition of a certain type for the passed token.
- hasCondition() : bool
- Determine if the passed token has a condition of one of the passed types.
Methods
getCondition()
Retrieve the position of a condition for the passed token.
public
static getCondition(File $phpcsFile, int $stackPtr[, int|string|array<string|int, int|string> $types = [] ][, bool $first = true ]) : int|false
If no types are specified, the first condition for the token - or if $first=false
,
the last condition - will be returned.
Main differences with the PHPCS version:
- The singular
$type
parameter has become the more flexible$types
parameter allowing to search for several types of conditions in one go. - The
$types
parameter is now optional.
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the token we are checking.
- $types : int|string|array<string|int, int|string> = []
-
Optional. The type(s) of tokens to search for.
- $first : bool = true
-
Optional. Whether to search for the first (outermost) (
true
) or the last (innermost) condition (false
) of the specified type(s).
Tags
Return values
int|false —Integer stack pointer to the condition; or FALSE
if the token
does not have the condition or has no conditions at all.
getFirstCondition()
Return the position of the first (outermost) condition of a certain type for the passed token.
public
static getFirstCondition(File $phpcsFile, int $stackPtr[, int|string|array<string|int, int|string> $types = [] ]) : int|false
If no types are specified, the first condition for the token, independently of type, will be returned.
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $stackPtr : int
-
The position of the token we are checking.
- $types : int|string|array<string|int, int|string> = []
-
Optional. The type(s) of tokens to search for.
Tags
Return values
int|false —Integer stack pointer to the condition; or FALSE
if the token
does not have the condition or has no conditions at all.
getLastCondition()
Return the position of the last (innermost) condition of a certain type for the passed token.
public
static getLastCondition(File $phpcsFile, int $stackPtr[, int|string|array<string|int, int|string> $types = [] ]) : int|false
If no types are specified, the last condition for the token, independently of type, will be returned.
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $stackPtr : int
-
The position of the token we are checking.
- $types : int|string|array<string|int, int|string> = []
-
Optional. The type(s) of tokens to search for.
Tags
Return values
int|false —Integer stack pointer to the condition; or FALSE
if the token
does not have the condition or has no conditions at all.
hasCondition()
Determine if the passed token has a condition of one of the passed types.
public
static hasCondition(File $phpcsFile, int $stackPtr, int|string|array<string|int, int|string> $types) : bool
This method is not significantly different from the PHPCS native version.
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the token we are checking.
- $types : int|string|array<string|int, int|string>
-
The type(s) of tokens to search for.