Parentheses
Utility functions for use when examining parenthesis tokens and arbitrary tokens wrapped in parentheses.
Table of Contents
| getOwner() | Get the pointer to the parentheses owner of an open/close parenthesis. | int|bool |
|---|---|---|
| isOwnerIn() | Check whether the parenthesis owner of an open/close parenthesis is within a limited set of valid owners. | bool |
| hasOwner() | Check whether the passed token is nested within parentheses owned by one of the valid owners. | bool |
| getFirstOpener() | Retrieve the position of the opener to the first (outer) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners. | int|bool |
| getFirstCloser() | Retrieve the position of the closer to the first (outer) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners. | int|bool |
| getFirstOwner() | Retrieve the position of the parentheses owner to the first (outer) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners. | int|bool |
| getLastOpener() | Retrieve the position of the opener to the last (inner) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners. | int|bool |
| getLastCloser() | Retrieve the position of the closer to the last (inner) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners. | int|bool |
| getLastOwner() | Retrieve the position of the parentheses owner to the last (inner) set of parentheses an arbitrary token is wrapped in where the parentheses owner is within the set of valid owners. | int|bool |
| firstOwnerIn() | Check whether the owner of a outermost wrapping set of parentheses of an arbitrary token is within a limited set of acceptable token types. | int|bool |
| lastOwnerIn() | Check whether the owner of a innermost wrapping set of parentheses of an arbitrary token is within a limited set of acceptable token types. | int|bool |
| nestedParensWalker() | Helper method. Retrieve the position of a parentheses opener for an arbitrary passed token. | int|bool |
Methods
getOwner()
Get the pointer to the parentheses owner of an open/close parenthesis.
public
static getOwner(
$phpcsFile :
File
, $stackPtr :
int
)
: int|bool
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of
T_OPEN/CLOSE_PARENTHESIStoken.
Tags
Return values
int|bool —Integer stack pointer to the parentheses owner or false if the parenthesis does not have a (direct) owner or if the token passed was not a parenthesis.
isOwnerIn()
Check whether the parenthesis owner of an open/close parenthesis is within a limited set of valid owners.
public
static isOwnerIn(
$phpcsFile :
File
, $stackPtr :
int
, $validOwners :
int|string|array
)
: bool
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of
T_OPEN/CLOSE_PARENTHESIStoken.- $validOwners : int|string|array
Array of token constants for the owners which should be considered valid.
Tags
Return values
bool —True if the owner is within the list of $validOwners, false if not and
if the parenthesis does not have a (direct) owner.
hasOwner()
Check whether the passed token is nested within parentheses owned by one of the valid owners.
public
static hasOwner(
$phpcsFile :
File
, $stackPtr :
int
, $validOwners :
int|string|array
)
: bool
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of the token we are checking.
- $validOwners : int|string|array
Array of token constants for the owners which should be considered valid.
Tags
Return values
boolgetFirstOpener()
Retrieve the position of the opener to the first (outer) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners.
public
static getFirstOpener(
$phpcsFile :
File
, $stackPtr :
int
[, $validOwners :
int|string|array
= [] ]
)
: int|bool
If no $validOwners are specified, the opener to the first set of parentheses surrounding
the token will be returned.
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of the token we are checking.
- $validOwners : int|string|array = []
Array of token constants for the owners which should be considered valid.
Tags
Return values
int|bool —Integer stack pointer to the parentheses opener or false if the token does not have parentheses owned by any of the valid owners or if the token is not nested in parentheses at all.
getFirstCloser()
Retrieve the position of the closer to the first (outer) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners.
public
static getFirstCloser(
$phpcsFile :
File
, $stackPtr :
int
[, $validOwners :
int|string|array
= [] ]
)
: int|bool
If no $validOwners are specified, the closer to the first set of parentheses surrounding
the token will be returned.
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of the token we are checking.
- $validOwners : int|string|array = []
Array of token constants for the owners which should be considered valid.
Tags
Return values
int|bool —Integer stack pointer to the parentheses closer or false if the token does not have parentheses owned by any of the valid owners or if the token is not nested in parentheses at all.
getFirstOwner()
Retrieve the position of the parentheses owner to the first (outer) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners.
public
static getFirstOwner(
$phpcsFile :
File
, $stackPtr :
int
[, $validOwners :
int|string|array
= [] ]
)
: int|bool
If no $validOwners are specified, the owner to the first set of parentheses surrounding
the token will be returned or false if the first set of parentheses does not have an owner.
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of the token we are checking.
- $validOwners : int|string|array = []
Array of token constants for the owners which should be considered valid.
Tags
Return values
int|bool —Integer stack pointer to the parentheses owner or false if the token does not have parentheses owned by any of the valid owners or if the token is not nested in parentheses at all.
getLastOpener()
Retrieve the position of the opener to the last (inner) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners.
public
static getLastOpener(
$phpcsFile :
File
, $stackPtr :
int
[, $validOwners :
int|string|array
= [] ]
)
: int|bool
If no $validOwners are specified, the opener to the last set of parentheses surrounding
the token will be returned.
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of the token we are checking.
- $validOwners : int|string|array = []
Array of token constants for the owners which should be considered valid.
Tags
Return values
int|bool —Integer stack pointer to the parentheses opener or false if the token does not have parentheses owned by any of the valid owners or if the token is not nested in parentheses at all.
getLastCloser()
Retrieve the position of the closer to the last (inner) set of parentheses an arbitrary token is wrapped in, where the parentheses owner is within the set of valid owners.
public
static getLastCloser(
$phpcsFile :
File
, $stackPtr :
int
[, $validOwners :
int|string|array
= [] ]
)
: int|bool
If no $validOwners are specified, the closer to the last set of parentheses surrounding
the token will be returned.
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of the token we are checking.
- $validOwners : int|string|array = []
Array of token constants for the owners which should be considered valid.
Tags
Return values
int|bool —Integer stack pointer to the parentheses closer or false if the token does not have parentheses owned by any of the valid owners or if the token is not nested in parentheses at all.
getLastOwner()
Retrieve the position of the parentheses owner to the last (inner) set of parentheses an arbitrary token is wrapped in where the parentheses owner is within the set of valid owners.
public
static getLastOwner(
$phpcsFile :
File
, $stackPtr :
int
[, $validOwners :
int|string|array
= [] ]
)
: int|bool
If no $validOwners are specified, the owner to the last set of parentheses surrounding
the token will be returned or false if the last set of parentheses does not have an owner.
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of the token we are checking.
- $validOwners : int|string|array = []
Array of token constants for the owners which should be considered valid.
Tags
Return values
int|bool —Integer stack pointer to the parentheses owner or false if the token does not have parentheses owned by any of the valid owners or if the token is not nested in parentheses at all.
firstOwnerIn()
Check whether the owner of a outermost wrapping set of parentheses of an arbitrary token is within a limited set of acceptable token types.
public
static firstOwnerIn(
$phpcsFile :
File
, $stackPtr :
int
, $validOwners :
int|string|array
)
: int|bool
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position in the stack of the token to verify.
- $validOwners : int|string|array
Array of token constants for the owners which should be considered valid.
Tags
Return values
int|bool —Integer stack pointer to the valid parentheses owner or false if the token was not wrapped in parentheses or if the outermost set of parentheses in which the token is wrapped does not have an owner within the set of owners considered valid.
lastOwnerIn()
Check whether the owner of a innermost wrapping set of parentheses of an arbitrary token is within a limited set of acceptable token types.
public
static lastOwnerIn(
$phpcsFile :
File
, $stackPtr :
int
, $validOwners :
int|string|array
)
: int|bool
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position in the stack of the token to verify.
- $validOwners : int|string|array
Array of token constants for the owners which should be considered valid.
Tags
Return values
int|bool —Integer stack pointer to the valid parentheses owner or false if the token was not wrapped in parentheses or if the innermost set of parentheses in which the token is wrapped does not have an owner within the set of owners considered valid.
nestedParensWalker()
Helper method. Retrieve the position of a parentheses opener for an arbitrary passed token.
private
static nestedParensWalker(
$phpcsFile :
File
, $stackPtr :
int
[, $validOwners :
int|string|array
= [] ]
[, $reverse :
bool
= false ]
)
: int|bool
If no $validOwners are specified, the opener to the first set of parentheses surrounding
the token - or if $reverse=true, the last set of parentheses - will be returned.
Parameters
- $phpcsFile : File
The file where this token was found.
- $stackPtr : int
The position of the token we are checking.
- $validOwners : int|string|array = []
Optional. Array of token constants for the owners which should be considered valid.
- $reverse : bool = false
Optional. Whether to search for the first/outermost (false) or the last/innermost (true) set of parentheses with the specified owner(s).
Tags
Return values
int|bool —Integer stack pointer to the parentheses opener or false if the token does not have parentheses owned by any of the valid owners or if the token is not nested in parentheses at all.