Operators
Utility functions for use when working with operators.
Table of Contents
| $extraUnaryIndicators | Tokens which indicate that a plus/minus is unary when they preceed it. | array |
|---|---|---|
| isReference() | Determine if the passed token is a reference operator. | bool |
| isUnaryPlusMinus() | Determine whether a T_MINUS/T_PLUS token is a unary operator. | bool |
| isShortTernary() | Determine whether a ternary is a short ternary/elvis operator, i.e. without "middle". | bool |
Properties
$extraUnaryIndicators
Tokens which indicate that a plus/minus is unary when they preceed it.
private
static array
$extraUnaryIndicators
= [\T_STRING_CONCAT => true, \T_RETURN => true, \T_ECHO => true, \T_PRINT => true, \T_YIELD => true, \T_COMMA => true, \T_OPEN_PARENTHESIS => true, \T_OPEN_SQUARE_BRACKET => true, \T_OPEN_SHORT_ARRAY => true, \T_OPEN_CURLY_BRACKET => true, \T_COLON => true, \T_INLINE_THEN => true, \T_INLINE_ELSE => true, \T_CASE => true]
Methods
isReference()
Determine if the passed token is a reference operator.
public
static isReference(
$phpcsFile :
File
, $stackPtr :
int
)
: bool
Main differences with the PHPCS version:
- Defensive coding against incorrect calls to this method.
- Improved handling of select tokenizer errors involving short lists/short arrays.
Parameters
- $phpcsFile : File
The file being scanned.
- $stackPtr : int
The position of the T_BITWISE_AND token.
Tags
Return values
bool —TRUE if the specified token position represents a reference. FALSE if the token represents a bitwise operator.
isUnaryPlusMinus()
Determine whether a T_MINUS/T_PLUS token is a unary operator.
public
static isUnaryPlusMinus(
$phpcsFile :
File
, $stackPtr :
int
)
: bool
Parameters
- $phpcsFile : File
The file being scanned.
- $stackPtr : int
The position of the plus/minus token.
Tags
Return values
bool —True if the token passed is a unary operator. False otherwise or if the token is not a T_PLUS/T_MINUS token.
isShortTernary()
Determine whether a ternary is a short ternary/elvis operator, i.e. without "middle".
public
static isShortTernary(
$phpcsFile :
File
, $stackPtr :
int
)
: bool
Parameters
- $phpcsFile : File
The file being scanned.
- $stackPtr : int
The position of the ternary then/else operator in the stack.
Tags
Return values
bool —True if short ternary, or false otherwise.