NoUselessElseFixer
extends AbstractNoUselessElseFixer
in package
Tags
Table of Contents
- getDefinition() : mixed
- {@inheritdoc}
- getPriority() : mixed
- {@inheritdoc}
- isCandidate() : mixed
- {@inheritdoc}
- applyFix() : mixed
- {@inheritdoc}
- isSuperfluousElse() : bool
- clearElse() : mixed
- fixEmptyElse() : mixed
- Remove tokens part of an `else` statement if not empty (i.e. no meaningful tokens inside).
- getPreviousBlock() : array<string|int, int>
- Return the first and last token index of the previous block.
- isInConditional() : bool
- isInConditionWithoutBraces() : bool
- For internal use only, as it is not perfect.
Methods
getDefinition()
{@inheritdoc}
public
getDefinition() : mixed
Return values
mixed —getPriority()
{@inheritdoc}
public
getPriority() : mixed
Must run before BracesFixer, CombineConsecutiveUnsetsFixer, NoBreakCommentFixer, NoExtraBlankLinesFixer, NoTrailingWhitespaceFixer, NoUselessReturnFixer, NoWhitespaceInBlankLineFixer, SimplifiedIfReturnFixer. Must run after NoAlternativeSyntaxFixer, NoEmptyStatementFixer, NoUnneededCurlyBracesFixer.
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 —isSuperfluousElse()
protected
isSuperfluousElse(Tokens $tokens, int $index) : bool
Parameters
- $tokens : Tokens
- $index : int
Return values
bool —clearElse()
private
clearElse(Tokens $tokens, int $index) : mixed
Parameters
- $tokens : Tokens
- $index : int
-
index of T_ELSE
Return values
mixed —fixEmptyElse()
Remove tokens part of an `else` statement if not empty (i.e. no meaningful tokens inside).
private
fixEmptyElse(Tokens $tokens, int $index) : mixed
Parameters
- $tokens : Tokens
- $index : int
-
T_ELSE index
Return values
mixed —getPreviousBlock()
Return the first and last token index of the previous block.
private
getPreviousBlock(Tokens $tokens, int $index) : array<string|int, int>
[0] First is either T_IF, T_ELSE or T_ELSEIF [1] Last is either '}' or ';' / T_CLOSE_TAG for short notation blocks
Parameters
- $tokens : Tokens
- $index : int
-
T_IF, T_ELSE, T_ELSEIF
Return values
array<string|int, int> —isInConditional()
private
isInConditional(Tokens $tokens, int $index, int $lowerLimitIndex) : bool
Parameters
- $tokens : Tokens
- $index : int
-
Index of the token to check
- $lowerLimitIndex : int
-
Lower limit index. Since the token to check will always be in a conditional we must stop checking at this index
Return values
bool —isInConditionWithoutBraces()
For internal use only, as it is not perfect.
private
isInConditionWithoutBraces(Tokens $tokens, int $index, int $lowerLimitIndex) : bool
Returns if the token at given index is part of a if/elseif/else statement
without }. Assumes not passing the last ;
/close tag of the statement, not
out of range index, etc.
Parameters
- $tokens : Tokens
- $index : int
-
Index of the token to check
- $lowerLimitIndex : int