PHPCSUtils

Parentheses
in package

Utility functions for use when examining parenthesis tokens and arbitrary tokens wrapped in parentheses.

In contrast to PHPCS natively, isset(), unset(), empty(), exit(), die() and eval() will be considered parentheses owners by the functions in this class.

Tags
since
1.0.0
since
1.0.0-alpha4

Added support for isset(), unset(), empty(), exit(), die() and eval() as parentheses owners to all applicable functions.

since
1.0.0-alpha4

Dropped support for PHPCS < 3.7.1.

Table of Contents

firstOwnerIn()  : int|false
Check whether the owner of the outermost wrapping set of parentheses of an arbitrary token is within a limited set of acceptable token types.
getFirstCloser()  : int|false
Retrieve the stack pointer to the parentheses closer of the first (outer) set of parentheses an arbitrary token is wrapped in.
getFirstOpener()  : int|false
Retrieve the stack pointer to the parentheses opener of the first (outer) set of parentheses an arbitrary token is wrapped in.
getFirstOwner()  : int|false
Retrieve the stack pointer to the parentheses owner of the first (outer) set of parentheses an arbitrary token is wrapped in.
getLastCloser()  : int|false
Retrieve the stack pointer to the parentheses closer of the last (inner) set of parentheses an arbitrary token is wrapped in.
getLastOpener()  : int|false
Retrieve the stack pointer to the parentheses opener of the last (inner) set of parentheses an arbitrary token is wrapped in.
getLastOwner()  : int|false
Retrieve the stack pointer to the parentheses owner of the last (inner) set of parentheses an arbitrary token is wrapped in.
getOwner()  : int|false
Get the stack pointer to the parentheses owner of an open/close parenthesis.
hasOwner()  : bool
Check whether the passed token is nested within parentheses owned by one of the valid owners.
isOwnerIn()  : bool
Check whether the parenthesis owner of an open/close parenthesis is within a limited set of valid owners.
lastOwnerIn()  : int|false
Check whether the owner of the innermost wrapping set of parentheses of an arbitrary token is within a limited set of acceptable token types.

Methods

firstOwnerIn()

Check whether the owner of the outermost wrapping set of parentheses of an arbitrary token is within a limited set of acceptable token types.

public static firstOwnerIn(File $phpcsFile, int $stackPtr, int|string|array<string|int, mixed> $validOwners) : int|false
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<string|int, mixed>

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
Return values
int|false

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.

getFirstCloser()

Retrieve the stack pointer to the parentheses closer of the first (outer) set of parentheses an arbitrary token is wrapped in.

public static getFirstCloser(File $phpcsFile, int $stackPtr[, int|string|array<string|int, mixed> $validOwners = [] ]) : int|false

If the optional $validOwners parameter is passed, the stack pointer to the closer to the first set of parentheses, which has an owner which is in the list of valid owners, will be returned. This may be a nested set of parentheses.

Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position of the token we are checking.

$validOwners : int|string|array<string|int, mixed> = []

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
Return values
int|false

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.

getFirstOpener()

Retrieve the stack pointer to the parentheses opener of the first (outer) set of parentheses an arbitrary token is wrapped in.

public static getFirstOpener(File $phpcsFile, int $stackPtr[, int|string|array<string|int, mixed> $validOwners = [] ]) : int|false

If the optional $validOwners parameter is passed, the stack pointer to the opener to the first set of parentheses, which has an owner which is in the list of valid owners, will be returned. This may be a nested set of parentheses.

Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position of the token we are checking.

$validOwners : int|string|array<string|int, mixed> = []

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
Return values
int|false

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.

getFirstOwner()

Retrieve the stack pointer to the parentheses owner of the first (outer) set of parentheses an arbitrary token is wrapped in.

public static getFirstOwner(File $phpcsFile, int $stackPtr[, int|string|array<string|int, mixed> $validOwners = [] ]) : int|false

If the optional $validOwners parameter is passed, the stack pointer to the owner of the first set of parentheses, which has an owner which is in the list of valid owners, will be returned. This may be a nested set of parentheses.

Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position of the token we are checking.

$validOwners : int|string|array<string|int, mixed> = []

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
Return values
int|false

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.

getLastCloser()

Retrieve the stack pointer to the parentheses closer of the last (inner) set of parentheses an arbitrary token is wrapped in.

public static getLastCloser(File $phpcsFile, int $stackPtr[, int|string|array<string|int, mixed> $validOwners = [] ]) : int|false

If the optional $validOwners parameter is passed, the stack pointer to the closer to the last set of parentheses, which has an owner which is in the list of valid owners, will be returned. This may be a set of parentheses higher up.

Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position of the token we are checking.

$validOwners : int|string|array<string|int, mixed> = []

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
Return values
int|false

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.

getLastOpener()

Retrieve the stack pointer to the parentheses opener of the last (inner) set of parentheses an arbitrary token is wrapped in.

public static getLastOpener(File $phpcsFile, int $stackPtr[, int|string|array<string|int, mixed> $validOwners = [] ]) : int|false

If the optional $validOwners parameter is passed, the stack pointer to the opener to the last set of parentheses, which has an owner which is in the list of valid owners, will be returned. This may be a set of parentheses higher up.

Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position of the token we are checking.

$validOwners : int|string|array<string|int, mixed> = []

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
Return values
int|false

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.

getLastOwner()

Retrieve the stack pointer to the parentheses owner of the last (inner) set of parentheses an arbitrary token is wrapped in.

public static getLastOwner(File $phpcsFile, int $stackPtr[, int|string|array<string|int, mixed> $validOwners = [] ]) : int|false

If the optional $validOwners parameter is passed, the stack pointer to the owner of the last set of parentheses, which has an owner which is in the list of valid owners, will be returned. This may be a set of parentheses higher up.

Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position of the token we are checking.

$validOwners : int|string|array<string|int, mixed> = []

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
Return values
int|false

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.

getOwner()

Get the stack pointer to the parentheses owner of an open/close parenthesis.

public static getOwner(File $phpcsFile, int $stackPtr) : int|false
Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position of T_OPEN/CLOSE_PARENTHESIS token.

Tags
since
1.0.0
since
1.0.0-alpha2

Added support for PHP 7.4 arrow functions.

Return values
int|false

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.

hasOwner()

Check whether the passed token is nested within parentheses owned by one of the valid owners.

public static hasOwner(File $phpcsFile, int $stackPtr, int|string|array<string|int, mixed> $validOwners) : 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<string|int, mixed>

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
Return values
bool

isOwnerIn()

Check whether the parenthesis owner of an open/close parenthesis is within a limited set of valid owners.

public static isOwnerIn(File $phpcsFile, int $stackPtr, int|string|array<string|int, mixed> $validOwners) : bool
Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position of T_OPEN/CLOSE_PARENTHESIS token.

$validOwners : int|string|array<string|int, mixed>

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
since
1.0.0-alpha2

Added support for PHP 7.4 arrow functions.

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.

lastOwnerIn()

Check whether the owner of the innermost wrapping set of parentheses of an arbitrary token is within a limited set of acceptable token types.

public static lastOwnerIn(File $phpcsFile, int $stackPtr, int|string|array<string|int, mixed> $validOwners) : int|false
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<string|int, mixed>

Array of token constants for the owners which should be considered valid.

Tags
since
1.0.0
Return values
int|false

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.

Search results