PHPCSUtils 1.0.10

Context
in package

FinalYes

Utility functions for examining in which context a certain token is used.

Example use-cases:

  • A sniff looking for the use of certain variables may want to disregard the "use" of these variables within a call to isset() or empty().
  • A sniff looking for incrementor/decrementors may want to disregard these when used as the third expression in a for() condition.
Tags
since
1.0.0

Table of Contents

Methods

inAttribute()  : bool
Check whether an arbitrary token is within an attribute.
inEmpty()  : bool
Check whether an arbitrary token is within a call to empty().
inForCondition()  : string|false
Check whether an arbitrary token is in a for condition and if so, in which part: the first, second or third expression.
inForeachCondition()  : string|false
Check whether an arbitrary token is in a foreach condition and if so, in which part: before or after the "as".
inIsset()  : bool
Check whether an arbitrary token is within a call to isset().
inUnset()  : bool
Check whether an arbitrary token is within a call to unset().

Methods

inAttribute()

Check whether an arbitrary token is within an attribute.

public static inAttribute(File $phpcsFile, int $stackPtr) : bool
Parameters
$phpcsFile : File

The file being scanned.

$stackPtr : int

The position of the token we are checking.

Tags
since
1.0.0
Return values
bool

inEmpty()

Check whether an arbitrary token is within a call to empty().

public static inEmpty(File $phpcsFile, int $stackPtr) : bool

This method is a thin, descriptive wrapper around the Parentheses::getLastOwner() method. For more complex/combined queries, it is recommended to call the Parentheses::getLastOwner() method directly.

Parameters
$phpcsFile : File

The file being scanned.

$stackPtr : int

The position of the token we are checking.

Tags
since
1.0.0
Return values
bool

inForCondition()

Check whether an arbitrary token is in a for condition and if so, in which part: the first, second or third expression.

public static inForCondition(File $phpcsFile, int $stackPtr) : string|false

Note: the semicolons separating the conditions are regarded as belonging with the expression before it.

Parameters
$phpcsFile : File

The file being scanned.

$stackPtr : int

The position of the token we are checking.

Tags
since
1.0.0
Return values
string|false

String 'expr1', 'expr2' or 'expr3' when the token is within a for condition. FALSE in all other cases, including for parse errors.

inForeachCondition()

Check whether an arbitrary token is in a foreach condition and if so, in which part: before or after the "as".

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

The file being scanned.

$stackPtr : int

The position of the token we are checking.

Tags
since
1.0.0
Return values
string|false

String 'beforeAs', 'as' or 'afterAs' when the token is within a foreach condition. FALSE in all other cases, including for parse errors.

inIsset()

Check whether an arbitrary token is within a call to isset().

public static inIsset(File $phpcsFile, int $stackPtr) : bool

This method is a thin, descriptive wrapper around the Parentheses::getLastOwner() method. For more complex/combined queries, it is recommended to call the Parentheses::getLastOwner() method directly.

Parameters
$phpcsFile : File

The file being scanned.

$stackPtr : int

The position of the token we are checking.

Tags
since
1.0.0
Return values
bool

inUnset()

Check whether an arbitrary token is within a call to unset().

public static inUnset(File $phpcsFile, int $stackPtr) : bool

This method is a thin, descriptive wrapper around the Parentheses::getLastOwner() method. For more complex/combined queries, it is recommended to call the Parentheses::getLastOwner() method directly.

Parameters
$phpcsFile : File

The file being scanned.

$stackPtr : int

The position of the token we are checking.

Tags
since
1.0.0
Return values
bool

        
On this page

Search results