Documentation

YodaStyleFixer extends AbstractFixer
in package
implements ConfigurableFixerInterface uses ConfigurableFixerTrait

FinalYes
Tags
author

Bram Gotink bram@gotink.me

author

Dariusz Rumiński dariusz.ruminski@gmail.com

implements

ConfigurableFixerInterface<_AutogeneratedInputConfiguration, _AutogeneratedComputedConfiguration>

phpstan-type

_AutogeneratedInputConfiguration array{ always_move_variable?: bool, equal?: bool|null, identical?: bool|null, less_and_greater?: bool|null }

phpstan-type

_AutogeneratedComputedConfiguration array{ always_move_variable: bool, equal: bool|null, identical: bool|null, less_and_greater: bool|null }

Table of Contents

Interfaces

ConfigurableFixerInterface

Properties

$candidatesMap  : array<int|string, Token>
$candidateTypes  : array<int, int|string>
$candidateTypesConfiguration  : array<int|string, null|bool>

Methods

getDefinition()  : FixerDefinitionInterface
Returns the definition of the fixer.
getPriority()  : int
Returns the priority of the fixer.
isCandidate()  : bool
Check if the fixer is a candidate for given Tokens collection.
applyFix()  : void
configurePostNormalisation()  : void
createConfigurationDefinition()  : FixerConfigurationResolverInterface
findComparisonEnd()  : int
Finds the end of the right-hand side of the comparison at the given index.
findComparisonStart()  : int
Finds the start of the left-hand side of the comparison at the given index.
fixTokens()  : Tokens
fixTokensCompare()  : int
Fixes the comparison at the given index.
fixTokensComparePart()  : Tokens
getCompareFixableInfo()  : null|array{left: array{start: int, end: int}, right: array{start: int, end: int}}
getLeftSideCompareFixableInfo()  : array{start: int, end: int}
getRightSideCompareFixableInfo()  : array{start: int, end: int}
isConstant()  : bool
isListStatement()  : bool
isOfLowerPrecedence()  : bool
Checks whether the given token has a lower precedence than `T_IS_EQUAL` or `T_IS_IDENTICAL`.
isOfLowerPrecedenceAssignment()  : bool
Checks whether the given assignment token has a lower precedence than `T_IS_EQUAL` or `T_IS_IDENTICAL`.
isVariable()  : bool
Checks whether the tokens between the given start and end describe a variable.
resolveConfiguration()  : void

Properties

$candidateTypesConfiguration

private array<int|string, null|bool> $candidateTypesConfiguration

Methods

getPriority()

Returns the priority of the fixer.

public getPriority() : int

Must run after IsNullFixer.

Return values
int

isCandidate()

Check if the fixer is a candidate for given Tokens collection.

public isCandidate(Tokens $tokens) : bool

Fixer is a candidate when the collection contains tokens that may be fixed during fixer work. This could be considered as some kind of bloom filter. When this method returns true then to the Tokens collection may or may not need a fixing, but when this method returns false then the Tokens collection need no fixing for sure.

Parameters
$tokens : Tokens
Return values
bool

configurePostNormalisation()

protected configurePostNormalisation() : void

findComparisonEnd()

Finds the end of the right-hand side of the comparison at the given index.

private findComparisonEnd(Tokens $tokens, int $index) : int

The right-hand side ends when an operator with a lower precedence is encountered or when the block level for (), } or [] goes below zero.

Parameters
$tokens : Tokens

The token list

$index : int

The index of the comparison

Return values
int

The last index of the right-hand side of the comparison

findComparisonStart()

Finds the start of the left-hand side of the comparison at the given index.

private findComparisonStart(Tokens $tokens, int $index) : int

The left-hand side ends when an operator with a lower precedence is encountered or when the block level for (), } or [] goes below zero.

Parameters
$tokens : Tokens

The token list

$index : int

The index of the comparison

Return values
int

The first index of the left-hand side of the comparison

fixTokensCompare()

Fixes the comparison at the given index.

private fixTokensCompare(Tokens $tokens, int $startLeft, int $endLeft, int $compareOperatorIndex, int $startRight, int $endRight) : int

A comparison is considered fixed when

  • both sides are a variable (e.g. $a === $b)
  • neither side is a variable (e.g. self::CONST === 3)
  • only the right-hand side is a variable (e.g. 3 === self::$var)

If the left-hand side and right-hand side of the given comparison are swapped, this function runs recursively on the previous left-hand-side.

Parameters
$tokens : Tokens
$startLeft : int
$endLeft : int
$compareOperatorIndex : int
$startRight : int
$endRight : int
Return values
int

an upper bound for all non-fixed comparisons

getCompareFixableInfo()

private getCompareFixableInfo(Tokens $tokens, int $index, bool $yoda) : null|array{left: array{start: int, end: int}, right: array{start: int, end: int}}
Parameters
$tokens : Tokens
$index : int
$yoda : bool
Return values
null|array{left: array{start: int, end: int}, right: array{start: int, end: int}}

getLeftSideCompareFixableInfo()

private getLeftSideCompareFixableInfo(Tokens $tokens, int $index) : array{start: int, end: int}
Parameters
$tokens : Tokens
$index : int
Return values
array{start: int, end: int}

getRightSideCompareFixableInfo()

private getRightSideCompareFixableInfo(Tokens $tokens, int $index) : array{start: int, end: int}
Parameters
$tokens : Tokens
$index : int
Return values
array{start: int, end: int}

isConstant()

private isConstant(Tokens $tokens, int $index, int $end) : bool
Parameters
$tokens : Tokens
$index : int
$end : int
Return values
bool

isListStatement()

private isListStatement(Tokens $tokens, int $index, int $end) : bool
Parameters
$tokens : Tokens
$index : int
$end : int
Return values
bool

isOfLowerPrecedence()

Checks whether the given token has a lower precedence than `T_IS_EQUAL` or `T_IS_IDENTICAL`.

private isOfLowerPrecedence(Token $token) : bool
Parameters
$token : Token

The token to check

Return values
bool

Whether the token has a lower precedence

isOfLowerPrecedenceAssignment()

Checks whether the given assignment token has a lower precedence than `T_IS_EQUAL` or `T_IS_IDENTICAL`.

private isOfLowerPrecedenceAssignment(Token $token) : bool
Parameters
$token : Token
Return values
bool

isVariable()

Checks whether the tokens between the given start and end describe a variable.

private isVariable(Tokens $tokens, int $start, int $end, bool $strict) : bool
Parameters
$tokens : Tokens

The token list

$start : int

The first index of the possible variable

$end : int

The last index of the possible variable

$strict : bool

Enable strict variable detection

Return values
bool

Whether the tokens describe a variable


        
On this page

Search results