NoUselessElseFixer
extends AbstractNoUselessElseFixer
in package
Table of Contents
Methods
- getDefinition() : FixerDefinitionInterface
- getPriority() : int
- isCandidate() : bool
- applyFix() : void
- isSuperfluousElse() : bool
- clearElse() : void
- fixEmptyElse() : void
- Remove tokens part of an `else` statement if not empty (i.e. no meaningful tokens inside).
- getPreviousBlock() : array{: 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()
public
getDefinition() : FixerDefinitionInterface
Return values
FixerDefinitionInterfacegetPriority()
public
getPriority() : int
Must run before BlankLineBeforeStatementFixer, BracesFixer, CombineConsecutiveUnsetsFixer, NoBreakCommentFixer, NoExtraBlankLinesFixer, NoTrailingWhitespaceFixer, NoUselessReturnFixer, NoWhitespaceInBlankLineFixer, SimplifiedIfReturnFixer, StatementIndentationFixer. Must run after NoAlternativeSyntaxFixer, NoEmptyStatementFixer, NoUnneededBracesFixer, NoUnneededCurlyBracesFixer.
Return values
intisCandidate()
public
isCandidate(Tokens $tokens) : bool
Parameters
- $tokens : Tokens
Return values
boolapplyFix()
protected
applyFix(SplFileInfo $file, Tokens $tokens) : void
Parameters
- $file : SplFileInfo
- $tokens : Tokens
isSuperfluousElse()
protected
isSuperfluousElse(Tokens $tokens, int $index) : bool
Parameters
- $tokens : Tokens
- $index : int
Return values
boolclearElse()
private
clearElse(Tokens $tokens, int $index) : void
Parameters
- $tokens : Tokens
- $index : int
-
index of T_ELSE
fixEmptyElse()
Remove tokens part of an `else` statement if not empty (i.e. no meaningful tokens inside).
private
fixEmptyElse(Tokens $tokens, int $index) : void
Parameters
- $tokens : Tokens
- $index : int
-
T_ELSE index
getPreviousBlock()
Return the first and last token index of the previous block.
private
getPreviousBlock(Tokens $tokens, int $index) : array{: 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{: 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
boolisInConditionWithoutBraces()
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 an 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