NoUnneededControlParenthesesFixer
extends AbstractFixer
in package
implements
ConfigurableFixerInterface
uses
ConfigurableFixerTrait
FinalYes
Tags
Table of Contents
Interfaces
Constants
- BEFORE_TYPES = [ ';', '{', [T_OPEN_TAG], [T_OPEN_TAG_WITH_ECHO], [T_ECHO], [T_PRINT], [T_RETURN], [T_THROW], [T_YIELD], [T_YIELD_FROM], [T_BREAK], [T_CONTINUE], // won't be fixed, but true in concept, helpful for fast check [T_REQUIRE], [T_REQUIRE_ONCE], [T_INCLUDE], [T_INCLUDE_ONCE], ]
- BLOCK_TYPES = [\PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_CURLY_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_DESTRUCTURING_SQUARE_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_DYNAMIC_PROP_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_PARENTHESIS_BRACE]
- CONFIG_OPTIONS = ['break', 'clone', 'continue', 'echo_print', 'negative_instanceof', 'others', 'return', 'switch_case', 'yield', 'yield_from']
- TOKEN_TYPE_CONFIG_MAP = [T_BREAK => 'break', T_CASE => 'switch_case', T_CONTINUE => 'continue', T_ECHO => 'echo_print', T_PRINT => 'echo_print', T_RETURN => 'return', T_YIELD => 'yield', T_YIELD_FROM => 'yield_from']
- TOKEN_TYPE_NO_CONFIG = [T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE]
Properties
- $noopTypes : array<int, array{: int}|string>
- $tokensAnalyzer : TokensAnalyzer
Methods
- __construct() : mixed
- 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
- createConfigurationDefinition() : FixerConfigurationResolverInterface
- closeCurlyBelongsToDynamicElement() : bool
- containsOperation() : bool
- getAfterAccess() : int
- getBeforePreUnaryOperation() : int
- getBlock() : null|Tokens::BLOCK_TYPE_*, isStart: bool}
- getConfigType() : string|null
- getIndexOfInstanceOfStatement() : int|null
- isAccess() : bool
- isCloneStatement() : bool
- isExitStatement() : bool
- isKnownNegativePre() : bool
- isPreUnaryOperation() : bool
- isSimpleAssignment() : bool
- isSingleStatement() : bool
- isUselessWrapped() : bool
- isWrappedCloneArgument() : bool
- isWrappedFnBody() : bool
- isWrappedForElement() : bool
- isWrappedInstanceOf() : bool
- isWrappedLanguageConstructArgument() : bool
- isWrappedPartOfOperation() : bool
- isWrappedSequenceElement() : bool
- removeBrace() : void
- removeUselessParenthesisPair() : void
Constants
BEFORE_TYPES
private
mixed
BEFORE_TYPES
= [
';',
'{',
[T_OPEN_TAG],
[T_OPEN_TAG_WITH_ECHO],
[T_ECHO],
[T_PRINT],
[T_RETURN],
[T_THROW],
[T_YIELD],
[T_YIELD_FROM],
[T_BREAK],
[T_CONTINUE],
// won't be fixed, but true in concept, helpful for fast check
[T_REQUIRE],
[T_REQUIRE_ONCE],
[T_INCLUDE],
[T_INCLUDE_ONCE],
]
BLOCK_TYPES
private
array<int, int>
BLOCK_TYPES
= [\PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_CURLY_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_DESTRUCTURING_SQUARE_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_DYNAMIC_PROP_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, \PhpCsFixer\Tokenizer\Tokens::BLOCK_TYPE_PARENTHESIS_BRACE]
CONFIG_OPTIONS
private
mixed
CONFIG_OPTIONS
= ['break', 'clone', 'continue', 'echo_print', 'negative_instanceof', 'others', 'return', 'switch_case', 'yield', 'yield_from']
TOKEN_TYPE_CONFIG_MAP
private
mixed
TOKEN_TYPE_CONFIG_MAP
= [T_BREAK => 'break', T_CASE => 'switch_case', T_CONTINUE => 'continue', T_ECHO => 'echo_print', T_PRINT => 'echo_print', T_RETURN => 'return', T_YIELD => 'yield', T_YIELD_FROM => 'yield_from']
TOKEN_TYPE_NO_CONFIG
private
mixed
TOKEN_TYPE_NO_CONFIG
= [T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE]
Properties
$noopTypes
private
array<int, array{: int}|string>
$noopTypes
$tokensAnalyzer
private
TokensAnalyzer
$tokensAnalyzer
Methods
__construct()
public
__construct() : mixed
getDefinition()
Returns the definition of the fixer.
public
getDefinition() : FixerDefinitionInterface
Return values
FixerDefinitionInterfacegetPriority()
Returns the priority of the fixer.
public
getPriority() : int
Must run before ConcatSpaceFixer, NoTrailingWhitespaceFixer. Must run after ModernizeTypesCastingFixer, NoAlternativeSyntaxFixer.
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
createConfigurationDefinition()
protected
createConfigurationDefinition() : FixerConfigurationResolverInterface
Return values
FixerConfigurationResolverInterfacecloseCurlyBelongsToDynamicElement()
private
closeCurlyBelongsToDynamicElement(Tokens $tokens, int $beforeOpenIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
Return values
boolcontainsOperation()
private
containsOperation(Tokens $tokens, int $startIndex, int $endIndex) : bool
Parameters
- $tokens : Tokens
- $startIndex : int
- $endIndex : int
Return values
boolgetAfterAccess()
private
getAfterAccess(Tokens $tokens, int $index) : int
Parameters
- $tokens : Tokens
- $index : int
Return values
intgetBeforePreUnaryOperation()
private
getBeforePreUnaryOperation(Tokens $tokens, int $index) : int
Parameters
- $tokens : Tokens
- $index : int
Return values
intgetBlock()
private
getBlock(Tokens $tokens, int $index, bool $isStart) : null|Tokens::BLOCK_TYPE_*, isStart: bool}
Parameters
- $tokens : Tokens
- $index : int
- $isStart : bool
Return values
null|Tokens::BLOCK_TYPE_*, isStart: bool}getConfigType()
private
getConfigType(Tokens $tokens, int $beforeOpenIndex) : string|null
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
Return values
string|nullgetIndexOfInstanceOfStatement()
private
getIndexOfInstanceOfStatement(Tokens $tokens, int $openIndex, int $closeIndex) : int|null
Parameters
- $tokens : Tokens
- $openIndex : int
- $closeIndex : int
Return values
int|nullisAccess()
private
isAccess(Tokens $tokens, int $index) : bool
Parameters
- $tokens : Tokens
- $index : int
Return values
boolisCloneStatement()
private
isCloneStatement(Tokens $tokens, int $beforeOpenIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
Return values
boolisExitStatement()
private
isExitStatement(Tokens $tokens, int $beforeOpenIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
Return values
boolisKnownNegativePre()
private
isKnownNegativePre(Token $token) : bool
Parameters
- $token : Token
Return values
boolisPreUnaryOperation()
private
isPreUnaryOperation(Tokens $tokens, int $index) : bool
Parameters
- $tokens : Tokens
- $index : int
Return values
boolisSimpleAssignment()
private
isSimpleAssignment(Tokens $tokens, int $beforeOpenIndex, int $afterCloseIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
- $afterCloseIndex : int
Return values
boolisSingleStatement()
private
isSingleStatement(Tokens $tokens, int $beforeOpenIndex, int $afterCloseIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
- $afterCloseIndex : int
Return values
boolisUselessWrapped()
private
isUselessWrapped(Tokens $tokens, int $beforeOpenIndex, int $afterCloseIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
- $afterCloseIndex : int
Return values
boolisWrappedCloneArgument()
private
isWrappedCloneArgument(Tokens $tokens, int $beforeOpenIndex, int $openIndex, int $closeIndex, int $afterCloseIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
- $openIndex : int
- $closeIndex : int
- $afterCloseIndex : int
Return values
boolisWrappedFnBody()
private
isWrappedFnBody(Tokens $tokens, int $beforeOpenIndex, int $afterCloseIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
- $afterCloseIndex : int
Return values
boolisWrappedForElement()
private
isWrappedForElement(Tokens $tokens, int $beforeOpenIndex, int $afterCloseIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
- $afterCloseIndex : int
Return values
boolisWrappedInstanceOf()
private
isWrappedInstanceOf(Tokens $tokens, int $instanceOfIndex, int $beforeOpenIndex, int $openIndex, int $closeIndex, int $afterCloseIndex) : bool
Parameters
- $tokens : Tokens
- $instanceOfIndex : int
- $beforeOpenIndex : int
- $openIndex : int
- $closeIndex : int
- $afterCloseIndex : int
Return values
boolisWrappedLanguageConstructArgument()
private
isWrappedLanguageConstructArgument(Tokens $tokens, int $beforeOpenIndex, int $afterCloseIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
- $afterCloseIndex : int
Return values
boolisWrappedPartOfOperation()
private
isWrappedPartOfOperation(Tokens $tokens, int $beforeOpenIndex, int $openIndex, int $closeIndex, int $afterCloseIndex) : bool
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
- $openIndex : int
- $closeIndex : int
- $afterCloseIndex : int
Return values
boolisWrappedSequenceElement()
private
isWrappedSequenceElement(Tokens $tokens, int $startIndex, int $endIndex) : bool
Parameters
- $tokens : Tokens
- $startIndex : int
- $endIndex : int
Return values
boolremoveBrace()
private
removeBrace(Tokens $tokens, int $index, bool $needsSpace) : void
Parameters
- $tokens : Tokens
- $index : int
- $needsSpace : bool
removeUselessParenthesisPair()
private
removeUselessParenthesisPair(Tokens $tokens, int $beforeOpenIndex, int $afterCloseIndex, int $openIndex, int $closeIndex, string|null $configType) : void
Parameters
- $tokens : Tokens
- $beforeOpenIndex : int
- $afterCloseIndex : int
- $openIndex : int
- $closeIndex : int
- $configType : string|null