Documentation

YodaStyleFixer extends AbstractFixer
in package
implements ConfigurationDefinitionFixerInterface

Tags
author

Bram Gotink bram@gotink.me

author

Dariusz RumiƄski dariusz.ruminski@gmail.com

author

SpacePossum

Interfaces, Classes and Traits

ConfigurationDefinitionFixerInterface

Table of Contents

$candidatesMap  : array<int|string, Token>
$candidateTypes  : array<string|int, int|string>
$candidateTypesConfiguration  : array<int|string, null|bool>
configure()  : mixed
{@inheritdoc}
getDefinition()  : mixed
{@inheritdoc}
getPriority()  : mixed
{@inheritdoc}
isCandidate()  : mixed
{@inheritdoc}
applyFix()  : mixed
{@inheritdoc}
createConfigurationDefinition()  : mixed
{@inheritdoc}
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<string|int, mixed>
getLeftSideCompareFixableInfo()  : array<string|int, mixed>
getRightSideCompareFixableInfo()  : array<string|int, mixed>
isConstant()  : mixed
isListStatement()  : bool
isOfLowerPrecedence()  : bool
Checks whether the given 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()  : mixed

Properties

$candidateTypes

private array<string|int, int|string> $candidateTypes

$candidateTypesConfiguration

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

Methods

configure()

{@inheritdoc}

public configure([array<string|int, mixed> $configuration = null ]) : mixed
Parameters
$configuration : array<string|int, mixed> = null
Return values
mixed

getDefinition()

{@inheritdoc}

public getDefinition() : mixed
Return values
mixed

getPriority()

{@inheritdoc}

public getPriority() : mixed

Must run after IsNullFixer.

Return values
mixed

isCandidate()

{@inheritdoc}

public isCandidate(Tokens $tokens) : mixed
Parameters
$tokens : Tokens
Return values
mixed

applyFix()

{@inheritdoc}

protected applyFix(SplFileInfo $file, Tokens $tokens) : mixed
Parameters
$file : SplFileInfo
$tokens : Tokens
Return values
mixed

createConfigurationDefinition()

{@inheritdoc}

protected createConfigurationDefinition() : mixed
Return values
mixed

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

a upper bound for all non-fixed comparisons

getCompareFixableInfo()

private getCompareFixableInfo(Tokens $tokens, int $index, bool $yoda) : null|array<string|int, mixed>
Parameters
$tokens : Tokens
$index : int
$yoda : bool
Return values
null|array<string|int, mixed>

getLeftSideCompareFixableInfo()

private getLeftSideCompareFixableInfo(Tokens $tokens, int $index) : array<string|int, mixed>
Parameters
$tokens : Tokens
$index : int
Return values
array<string|int, mixed>

getRightSideCompareFixableInfo()

private getRightSideCompareFixableInfo(Tokens $tokens, int $index) : array<string|int, mixed>
Parameters
$tokens : Tokens
$index : int
Return values
array<string|int, mixed>

isConstant()

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

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

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

resolveConfiguration()

private resolveConfiguration() : mixed
Return values
mixed

Search results