Conditions
Utility functions for use when examining token conditions.
Table of Contents
| getCondition() | Retrieve the position of a condition for the passed token. | int|bool |
|---|---|---|
| hasCondition() | Determine if the passed token has a condition of one of the passed types. | bool |
| getFirstCondition() | Return the position of the first (outermost) condition of a certain type for the passed token. | int|bool |
| getLastCondition() | Return the position of the last (innermost) condition of a certain type for the passed token. | int|bool |
Methods
getCondition()
Retrieve the position of a condition for the passed token.
public
static getCondition(
$phpcsFile :
File
, $stackPtr :
int
[, $types :
int|string|array
= [] ]
[, $first :
bool
= true ]
)
: int|bool
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
$typeparameter has become the more flexible$typesparameter allowing to search for several types of conditions in one go. - The
$typesparameter is now optional.
Parameters
- $phpcsFile : File
The file being scanned.
- $stackPtr : int
The position of the token we are checking.
- $types : int|string|array = []
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|bool —Integer stack pointer to the condition or FALSE if the token does not have the condition.
hasCondition()
Determine if the passed token has a condition of one of the passed types.
public
static hasCondition(
$phpcsFile :
File
, $stackPtr :
int
, $types :
int|string|array
)
: 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
The type(s) of tokens to search for.
Tags
Return values
boolgetFirstCondition()
Return the position of the first (outermost) condition of a certain type for the passed token.
public
static getFirstCondition(
$phpcsFile :
File
, $stackPtr :
int
[, $types :
int|string|array
= [] ]
)
: int|bool
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 = []
Optional. The type(s) of tokens to search for.
Tags
Return values
int|bool —StackPtr to the condition or false if the token does not have the condition.
getLastCondition()
Return the position of the last (innermost) condition of a certain type for the passed token.
public
static getLastCondition(
$phpcsFile :
File
, $stackPtr :
int
[, $types :
int|string|array
= [] ]
)
: int|bool
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 = []
Optional. The type(s) of tokens to search for.
Tags
Return values
int|bool —StackPtr to the condition or false if the token does not have the condition.