Operators
in package
Utility functions for use when working with operators.
Tags
Table of Contents
Properties
- $extraUnaryIndicators : array<int|string, true>
- Tokens which indicate that a plus/minus is unary when they preceed it.
Methods
- isReference() : bool
- Determine if the passed token is a reference operator.
- isShortTernary() : bool
- Determine whether a ternary is a short ternary/elvis operator, i.e. without "middle".
- isUnaryPlusMinus() : bool
- Determine whether a T_MINUS/T_PLUS token is a unary operator.
Properties
$extraUnaryIndicators
Tokens which indicate that a plus/minus is unary when they preceed it.
private
static array<int|string, true>
$extraUnaryIndicators
= [\T_STRING_CONCAT => true, \T_RETURN => true, \T_EXIT => true, \T_CONTINUE => true, \T_BREAK => 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, \T_FN_ARROW => true, \T_MATCH_ARROW => true]
Note: value is irrelevant, only key is used.
Tags
Methods
isReference()
Determine if the passed token is a reference operator.
public
static isReference(File $phpcsFile, int $stackPtr) : bool
Main differences with the PHPCS version:
- Defensive coding against incorrect calls to this method.
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the
T_BITWISE_ANDtoken.
Tags
Return values
bool —TRUE if the specified token position represents a reference.
FALSE if the token represents a bitwise operator.
isShortTernary()
Determine whether a ternary is a short ternary/elvis operator, i.e. without "middle".
public
static isShortTernary(File $phpcsFile, int $stackPtr) : 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.
isUnaryPlusMinus()
Determine whether a T_MINUS/T_PLUS token is a unary operator.
public
static isUnaryPlusMinus(File $phpcsFile, int $stackPtr) : 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, i.e. if the token is an arithmetic operator,
or if the token is not a T_PLUS/T_MINUS token.