PHPCSUtils

Operators
in package

Utility functions for use when working with operators.

Tags
link

PHP manual on operators.

since
1.0.0

The isReference() method is based on and inspired by the method of the same name in the PHPCS native File class. Also see BCFile. The isUnaryPlusMinus() method is, in part, inspired by the Squiz.WhiteSpace.OperatorSpacing sniff.

since
1.0.0-alpha4

Dropped support for PHPCS < 3.7.1.

Table of Contents

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.

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_AND token.

Tags
see
File::isReference()

Original source.

see
BCFile::isReference()

Cross-version compatible version of the original.

since
1.0.0
since
1.0.0-alpha2

Added support for PHP 7.4 arrow functions.

since
1.0.0-alpha4

Added support for PHP 8.0 identifier name tokenization.

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
since
1.0.0
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
since
1.0.0
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.

Search results