diff --git a/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php b/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php index 3bf8dfd3cd2..c3eb4fd1ac7 100644 --- a/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php +++ b/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php @@ -19,7 +19,6 @@ use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; -use PhpCsFixer\FixerConfiguration\InvalidOptionsForEnvException; use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; @@ -91,10 +90,6 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->setAllowedTypes(['bool']) ->setDefault(false) ->setNormalizer(static function (Options $options, $value) { - if (\PHP_VERSION_ID < 70300 && $value) { - throw new InvalidOptionsForEnvException('"after_heredoc" option can only be enabled with PHP 7.3+.'); - } - return $value; }) ->getOption(), diff --git a/src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php b/src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php index 9a3cf4e1547..51099dff0a0 100644 --- a/src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php +++ b/src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php @@ -112,10 +112,6 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->setAllowedTypes(['bool']) ->setDefault(false) ->setNormalizer(static function (Options $options, $value) { - if (\PHP_VERSION_ID < 70300 && $value) { - throw new InvalidOptionsForEnvException('"after_heredoc" option can only be enabled with PHP 7.3+.'); - } - return $value; }) ->getOption(), @@ -124,10 +120,6 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->setAllowedValues([new AllowedValueSubset([self::ELEMENTS_ARRAYS, self::ELEMENTS_ARGUMENTS, self::ELEMENTS_PARAMETERS])]) ->setDefault([self::ELEMENTS_ARRAYS]) ->setNormalizer(static function (Options $options, $value) { - if (\PHP_VERSION_ID < 70300 && \in_array(self::ELEMENTS_ARGUMENTS, $value, true)) { - throw new InvalidOptionsForEnvException(sprintf('"%s" option can only be enabled with PHP 7.3+.', self::ELEMENTS_ARGUMENTS)); - } - if (\PHP_VERSION_ID < 80000 && \in_array(self::ELEMENTS_PARAMETERS, $value, true)) { throw new InvalidOptionsForEnvException(sprintf('"%s" option can only be enabled with PHP 8.0+.', self::ELEMENTS_PARAMETERS)); } diff --git a/src/Fixer/ControlStructure/YodaStyleFixer.php b/src/Fixer/ControlStructure/YodaStyleFixer.php index 8cf4eba86dd..348d926f47a 100644 --- a/src/Fixer/ControlStructure/YodaStyleFixer.php +++ b/src/Fixer/ControlStructure/YodaStyleFixer.php @@ -475,24 +475,20 @@ private function isOfLowerPrecedenceAssignment(Token $token): bool if (null === $tokens) { $tokens = [ - T_AND_EQUAL, // &= - T_CONCAT_EQUAL, // .= - T_DIV_EQUAL, // /= - T_MINUS_EQUAL, // -= - T_MOD_EQUAL, // %= - T_MUL_EQUAL, // *= - T_OR_EQUAL, // |= - T_PLUS_EQUAL, // += - T_POW_EQUAL, // **= - T_SL_EQUAL, // <<= - T_SR_EQUAL, // >>= - T_XOR_EQUAL, // ^= + T_AND_EQUAL, // &= + T_CONCAT_EQUAL, // .= + T_DIV_EQUAL, // /= + T_MINUS_EQUAL, // -= + T_MOD_EQUAL, // %= + T_MUL_EQUAL, // *= + T_OR_EQUAL, // |= + T_PLUS_EQUAL, // += + T_POW_EQUAL, // **= + T_SL_EQUAL, // <<= + T_SR_EQUAL, // >>= + T_XOR_EQUAL, // ^= + T_COALESCE_EQUAL, // ??= ]; - - // @TODO: drop condition when PHP 7.4+ is required - if (\defined('T_COALESCE_EQUAL')) { - $tokens[] = T_COALESCE_EQUAL; // ??= - } } return $token->equals('=') || $token->isGivenKind($tokens); diff --git a/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php b/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php index af633fc8417..d8243cba4a9 100644 --- a/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php +++ b/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php @@ -57,7 +57,7 @@ final class FunctionDeclarationFixer extends AbstractFixer implements Configurab */ public function isCandidate(Tokens $tokens): bool { - return $tokens->isTokenKindFound(T_FUNCTION) || (\PHP_VERSION_ID >= 70400 && $tokens->isTokenKindFound(T_FN)); + return $tokens->isAnyTokenKindsFound([T_FUNCTION, T_FN]); } /** @@ -123,10 +123,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void for ($index = $tokens->count() - 1; $index >= 0; --$index) { $token = $tokens[$index]; - if ( - !$token->isGivenKind(T_FUNCTION) - && (\PHP_VERSION_ID < 70400 || !$token->isGivenKind(T_FN)) - ) { + if (!$token->isGivenKind([T_FUNCTION, T_FN])) { continue; } diff --git a/src/Fixer/FunctionNotation/FunctionTypehintSpaceFixer.php b/src/Fixer/FunctionNotation/FunctionTypehintSpaceFixer.php index 53a03ebb61a..f1f16cc9a71 100644 --- a/src/Fixer/FunctionNotation/FunctionTypehintSpaceFixer.php +++ b/src/Fixer/FunctionNotation/FunctionTypehintSpaceFixer.php @@ -46,11 +46,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - if (\PHP_VERSION_ID >= 70400 && $tokens->isTokenKindFound(T_FN)) { - return true; - } - - return $tokens->isTokenKindFound(T_FUNCTION); + return $tokens->isAnyTokenKindsFound([T_FUNCTION, T_FN]); } /** @@ -63,10 +59,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void for ($index = $tokens->count() - 1; $index >= 0; --$index) { $token = $tokens[$index]; - if ( - !$token->isGivenKind(T_FUNCTION) - && (\PHP_VERSION_ID < 70400 || !$token->isGivenKind(T_FN)) - ) { + if (!$token->isGivenKind([T_FUNCTION, T_FN])) { continue; } diff --git a/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php b/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php index 5ccb51794ed..d09ebf4255b 100644 --- a/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php +++ b/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php @@ -20,7 +20,6 @@ use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; -use PhpCsFixer\FixerConfiguration\InvalidOptionsForEnvException; use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; @@ -136,11 +135,7 @@ public function getPriority(): int */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { - $expectedTokens = [T_LIST, T_FUNCTION, CT::T_USE_LAMBDA]; - - if (\PHP_VERSION_ID >= 70400) { - $expectedTokens[] = T_FN; - } + $expectedTokens = [T_LIST, T_FUNCTION, CT::T_USE_LAMBDA, T_FN]; for ($index = $tokens->count() - 1; $index > 0; --$index) { $token = $tokens[$index]; @@ -191,10 +186,6 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->setAllowedTypes(['bool']) ->setDefault(false) ->setNormalizer(static function (Options $options, $value) { - if (\PHP_VERSION_ID < 70300 && $value) { - throw new InvalidOptionsForEnvException('"after_heredoc" option can only be enabled with PHP 7.3+.'); - } - return $value; }) ->getOption(), diff --git a/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php b/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php index 89a5b480808..a41ca009788 100644 --- a/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php +++ b/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php @@ -62,11 +62,7 @@ public function getPriority(): int */ public function isCandidate(Tokens $tokens): bool { - if (\PHP_VERSION_ID >= 70400 && $tokens->isTokenKindFound(T_FN)) { - return true; - } - - return $tokens->isTokenKindFound(T_FUNCTION); + return $tokens->isAnyTokenKindsFound([T_FUNCTION, T_FN]); } /** @@ -82,10 +78,7 @@ public function isRisky(): bool */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { - $functionKinds = [T_FUNCTION]; - if (\defined('T_FN')) { - $functionKinds[] = T_FN; - } + $functionKinds = [T_FUNCTION, T_FN]; for ($i = 0, $l = $tokens->count(); $i < $l; ++$i) { if (!$tokens[$i]->isGivenKind($functionKinds)) { diff --git a/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php b/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php index 1d12b109530..a6c3f7e20ce 100644 --- a/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php +++ b/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php @@ -58,15 +58,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - if (!$tokens->isTokenKindFound(T_VARIABLE)) { - return false; - } - - if (\PHP_VERSION_ID >= 70400 && $tokens->isTokenKindFound(T_FN)) { - return true; - } - - return $tokens->isTokenKindFound(T_FUNCTION); + return $tokens->isTokenKindFound(T_VARIABLE) && $tokens->isAnyTokenKindsFound([T_FUNCTION, T_FN]); } /** @@ -98,11 +90,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { $functionsAnalyzer = new FunctionsAnalyzer(); - $tokenKinds = [T_FUNCTION]; - - if (\PHP_VERSION_ID >= 70400) { - $tokenKinds[] = T_FN; - } + $tokenKinds = [T_FUNCTION, T_FN]; for ($index = $tokens->count() - 1; $index >= 0; --$index) { $token = $tokens[$index]; diff --git a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php index 2c767d06dcb..b7cde6f9662 100644 --- a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php @@ -76,7 +76,7 @@ class Foo { */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70400 && $tokens->isTokenKindFound(T_DOC_COMMENT); + return $tokens->isTokenKindFound(T_DOC_COMMENT); } /** diff --git a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php index 1c7584692e8..5b316b49260 100644 --- a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php @@ -110,11 +110,7 @@ public function create($prototype) { */ public function isCandidate(Tokens $tokens): bool { - if (\PHP_VERSION_ID >= 70400 && $tokens->isTokenKindFound(T_FN)) { - return true; - } - - return $tokens->isTokenKindFound(T_FUNCTION); + return $tokens->isAnyTokenKindsFound([T_FUNCTION, T_FN]); } /** @@ -143,10 +139,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } for ($index = $tokens->count() - 1; 0 < $index; --$index) { - if ( - !$tokens[$index]->isGivenKind(T_FUNCTION) - && (\PHP_VERSION_ID < 70400 || !$tokens[$index]->isGivenKind(T_FN)) - ) { + if (!$tokens[$index]->isGivenKind([T_FUNCTION, T_FN])) { continue; } diff --git a/src/Fixer/FunctionNotation/StaticLambdaFixer.php b/src/Fixer/FunctionNotation/StaticLambdaFixer.php index 1220bb459a9..211f7c946a4 100644 --- a/src/Fixer/FunctionNotation/StaticLambdaFixer.php +++ b/src/Fixer/FunctionNotation/StaticLambdaFixer.php @@ -43,11 +43,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - if (\PHP_VERSION_ID >= 70400 && $tokens->isTokenKindFound(T_FN)) { - return true; - } - - return $tokens->isTokenKindFound(T_FUNCTION); + return $tokens->isAnyTokenKindsFound([T_FUNCTION, T_FN]); } /** @@ -64,11 +60,7 @@ public function isRisky(): bool protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { $analyzer = new TokensAnalyzer($tokens); - $expectedFunctionKinds = [T_FUNCTION]; - - if (\PHP_VERSION_ID >= 70400) { - $expectedFunctionKinds[] = T_FN; - } + $expectedFunctionKinds = [T_FUNCTION, T_FN]; for ($index = $tokens->count() - 4; $index > 0; --$index) { if (!$tokens[$index]->isGivenKind($expectedFunctionKinds) || !$analyzer->isLambda($index)) { diff --git a/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php b/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php index 8a5733745c5..2df90852a9f 100644 --- a/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php +++ b/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php @@ -59,7 +59,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70400 && $tokens->isAllTokenKindsFound([T_FUNCTION, T_RETURN]); + return $tokens->isAllTokenKindsFound([T_FUNCTION, T_RETURN]); } /** diff --git a/src/Fixer/Operator/AssignNullCoalescingToCoalesceEqualFixer.php b/src/Fixer/Operator/AssignNullCoalescingToCoalesceEqualFixer.php index 399811c1ebe..bbf1602d32b 100644 --- a/src/Fixer/Operator/AssignNullCoalescingToCoalesceEqualFixer.php +++ b/src/Fixer/Operator/AssignNullCoalescingToCoalesceEqualFixer.php @@ -58,7 +58,7 @@ public function getPriority(): int */ public function isCandidate(Tokens $tokens): bool { - return \defined('T_COALESCE_EQUAL') && $tokens->isTokenKindFound(T_COALESCE); + return $tokens->isTokenKindFound(T_COALESCE); } /** diff --git a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php index 1da5fa8ad07..3aad82bd97e 100644 --- a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php +++ b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php @@ -468,11 +468,6 @@ private function resolveOperatorsFromConfig(): array } } - // @TODO: drop condition when PHP 7.4+ is required - if (!\defined('T_COALESCE_EQUAL')) { - unset($operators['??=']); - } - return $operators; } diff --git a/src/Fixer/Whitespace/HeredocIndentationFixer.php b/src/Fixer/Whitespace/HeredocIndentationFixer.php index a3305626ebc..338d9142bff 100644 --- a/src/Fixer/Whitespace/HeredocIndentationFixer.php +++ b/src/Fixer/Whitespace/HeredocIndentationFixer.php @@ -88,7 +88,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70300 && $tokens->isTokenKindFound(T_START_HEREDOC); + return $tokens->isTokenKindFound(T_START_HEREDOC); } /** diff --git a/src/Linter/TokenizerLinter.php b/src/Linter/TokenizerLinter.php index e017bbc42bb..8b70421c82b 100644 --- a/src/Linter/TokenizerLinter.php +++ b/src/Linter/TokenizerLinter.php @@ -27,16 +27,6 @@ */ final class TokenizerLinter implements LinterInterface { - public function __construct() - { - if ( - // @TODO: drop condition when PHP 7.3+ is required - false === class_exists(\CompileError::class) - ) { - throw new UnavailableLinterException('Cannot use tokenizer as linter.'); - } - } - /** * {@inheritdoc} */ diff --git a/src/Tokenizer/AbstractTypeTransformer.php b/src/Tokenizer/AbstractTypeTransformer.php index 53fa51355f6..c8636eee0c1 100644 --- a/src/Tokenizer/AbstractTypeTransformer.php +++ b/src/Tokenizer/AbstractTypeTransformer.php @@ -62,11 +62,7 @@ protected function doProcess(Tokens $tokens, int $index, $originalToken): void return; } - $functionKinds = [[T_FUNCTION]]; - if (\defined('T_FN')) { - $functionKinds[] = [T_FN]; - } - + $functionKinds = [[T_FUNCTION], [T_FN]]; $functionIndex = $tokens->getPrevTokenOfKind($prevIndex, $functionKinds); if (null === $functionIndex) { diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index 2e589de719a..42d4081f8a0 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -280,10 +280,7 @@ public function isAnonymousClass(int $index): bool */ public function isLambda(int $index): bool { - if ( - !$this->tokens[$index]->isGivenKind(T_FUNCTION) - && (\PHP_VERSION_ID < 70400 || !$this->tokens[$index]->isGivenKind(T_FN)) - ) { + if (!$this->tokens[$index]->isGivenKind([T_FUNCTION, T_FN])) { throw new \LogicException(sprintf('No T_FUNCTION or T_FN at given index %d, got "%s".', $index, $this->tokens[$index]->getName())); } @@ -563,12 +560,8 @@ public function isBinaryOperator(int $index): bool T_XOR_EQUAL => true, // ^= T_SPACESHIP => true, // <=> T_COALESCE => true, // ?? + T_COALESCE_EQUAL => true, // ??= ]; - - // @TODO: drop condition when PHP 7.4+ is required - if (\defined('T_COALESCE_EQUAL')) { - $arrayOperators[T_COALESCE_EQUAL] = true; // ??= - } } $tokens = $this->tokens; diff --git a/src/Tokenizer/Transformer/ReturnRefTransformer.php b/src/Tokenizer/Transformer/ReturnRefTransformer.php index 06d7c9dd54f..c2b2b4a81fc 100644 --- a/src/Tokenizer/Transformer/ReturnRefTransformer.php +++ b/src/Tokenizer/Transformer/ReturnRefTransformer.php @@ -41,12 +41,7 @@ public function getRequiredPhpVersionId(): int */ public function process(Tokens $tokens, Token $token, int $index): void { - $prevKinds = [T_FUNCTION]; - if (\PHP_VERSION_ID >= 70400) { - $prevKinds[] = T_FN; - } - - if ($token->equals('&') && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind($prevKinds)) { + if ($token->equals('&') && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind([T_FUNCTION, T_FN])) { $tokens[$index] = new Token([CT::T_RETURN_REF, '&']); } } diff --git a/src/Tokenizer/Transformer/TypeColonTransformer.php b/src/Tokenizer/Transformer/TypeColonTransformer.php index 2a70892d6e7..9969f9bcaa5 100644 --- a/src/Tokenizer/Transformer/TypeColonTransformer.php +++ b/src/Tokenizer/Transformer/TypeColonTransformer.php @@ -71,13 +71,7 @@ public function process(Tokens $tokens, Token $token, int $index): void $prevToken = $tokens[$prevIndex]; } - $prevKinds = [T_FUNCTION, CT::T_RETURN_REF, CT::T_USE_LAMBDA]; - - if (\defined('T_FN')) { // @TODO: drop condition when PHP 7.4+ is required - $prevKinds[] = T_FN; - } - - if ($prevToken->isGivenKind($prevKinds)) { + if ($prevToken->isGivenKind([T_FUNCTION, CT::T_RETURN_REF, CT::T_USE_LAMBDA, T_FN])) { $tokens[$index] = new Token([CT::T_TYPE_COLON, ':']); } }