YodaStyleFixer
extends AbstractFixer
in package
implements
ConfigurableFixerInterface
uses
ConfigurableFixerTrait
Tags
Table of Contents
Interfaces
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
$candidatesMap
private
array<int|string, Token>
$candidatesMap
$candidateTypes
private
array<int, int|string>
$candidateTypes
$candidateTypesConfiguration
private
array<int|string, null|bool>
$candidateTypesConfiguration
Methods
getDefinition()
Returns the definition of the fixer.
public
getDefinition() : FixerDefinitionInterface
Return values
FixerDefinitionInterfacegetPriority()
Returns the priority of the fixer.
public
getPriority() : int
Must run after IsNullFixer.
Return values
intisCandidate()
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
boolapplyFix()
protected
applyFix(SplFileInfo $file, Tokens $tokens) : void
Parameters
- $file : SplFileInfo
- $tokens : Tokens
configurePostNormalisation()
protected
configurePostNormalisation() : void
createConfigurationDefinition()
protected
createConfigurationDefinition() : FixerConfigurationResolverInterface
Return values
FixerConfigurationResolverInterfacefindComparisonEnd()
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
fixTokens()
private
fixTokens(Tokens $tokens) : Tokens
Parameters
- $tokens : Tokens
Return values
TokensfixTokensCompare()
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
fixTokensComparePart()
private
fixTokensComparePart(Tokens $tokens, int $start, int $end) : Tokens
Parameters
- $tokens : Tokens
- $start : int
- $end : int
Return values
TokensgetCompareFixableInfo()
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
boolisListStatement()
private
isListStatement(Tokens $tokens, int $index, int $end) : bool
Parameters
- $tokens : Tokens
- $index : int
- $end : int
Return values
boolisOfLowerPrecedence()
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
boolisVariable()
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() : void