diff --git a/src/AbstractFunctionReferenceFixer.php b/src/AbstractFunctionReferenceFixer.php index 97a92deff10..696e707e0f9 100644 --- a/src/AbstractFunctionReferenceFixer.php +++ b/src/AbstractFunctionReferenceFixer.php @@ -69,6 +69,6 @@ protected function find(string $functionNameToSearch, Tokens $tokens, int $start return $this->find($functionNameToSearch, $tokens, $openParenthesis, $end); } - return [$functionName, $openParenthesis, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesis)]; + return [$functionName, $openParenthesis, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openParenthesis)]; } } diff --git a/src/AbstractNoUselessElseFixer.php b/src/AbstractNoUselessElseFixer.php index 48cd7763e09..34c6541b6a9 100644 --- a/src/AbstractNoUselessElseFixer.php +++ b/src/AbstractNoUselessElseFixer.php @@ -100,7 +100,7 @@ private function getPreviousBlock(Tokens $tokens, int $index): array $close = $previous = $tokens->getPrevMeaningfulToken($index); // short 'if' detection if ($tokens[$close]->equals('}')) { - $previous = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $close); + $previous = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $close); } $open = $tokens->getPrevTokenOfKind($previous, [[T_IF], [T_ELSE], [T_ELSEIF]]); @@ -132,7 +132,7 @@ private function isInConditional(Tokens $tokens, int $index, int $lowerLimitInde // token is always ')' here. // If it is part of the condition the token is always in, return false. // If it is not it is a nested condition so return true - $open = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $candidateIndex); + $open = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $candidateIndex); return $tokens->getPrevMeaningfulToken($open) > $lowerLimitIndex; } @@ -178,7 +178,7 @@ private function isInConditionWithoutBraces(Tokens $tokens, int $index, int $low } $index = $tokens->findBlockStart( - Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + Tokens::BLOCK_TYPE_PARENTHESIS, $index ); diff --git a/src/Fixer/Alias/ArrayPushFixer.php b/src/Fixer/Alias/ArrayPushFixer.php index 9023bbd37d9..613f802bce0 100644 --- a/src/Fixer/Alias/ArrayPushFixer.php +++ b/src/Fixer/Alias/ArrayPushFixer.php @@ -78,13 +78,13 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $openBraceIndex = $tokens->getNextMeaningfulToken($callIndex); $blockType = Tokens::detectBlockType($tokens[$openBraceIndex]); - if (null === $blockType || Tokens::BLOCK_TYPE_PARENTHESIS_BRACE !== $blockType['type']) { + if (null === $blockType || Tokens::BLOCK_TYPE_PARENTHESIS !== $blockType['type']) { continue; } // figure out where the arguments list closes - $closeBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openBraceIndex); + $closeBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openBraceIndex); // meaningful after `)` must be `;`, `? >` or nothing diff --git a/src/Fixer/Alias/ModernizeStrposFixer.php b/src/Fixer/Alias/ModernizeStrposFixer.php index b060b4e63ce..acf3c6c9813 100644 --- a/src/Fixer/Alias/ModernizeStrposFixer.php +++ b/src/Fixer/Alias/ModernizeStrposFixer.php @@ -108,7 +108,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // assert called with 2 arguments $openIndex = $tokens->getNextMeaningfulToken($index); - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openIndex); $arguments = $argumentsAnalyzer->getArguments($tokens, $openIndex, $closeIndex); if (2 !== \count($arguments)) { diff --git a/src/Fixer/Alias/NoAliasFunctionsFixer.php b/src/Fixer/Alias/NoAliasFunctionsFixer.php index b56d0c4051a..1a6080200d3 100644 --- a/src/Fixer/Alias/NoAliasFunctionsFixer.php +++ b/src/Fixer/Alias/NoAliasFunctionsFixer.php @@ -268,7 +268,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if (\is_array($this->aliases[$tokenContent])) { [$alias, $numberOfArguments] = $this->aliases[$tokenContent]; - $count = $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesis)); + $count = $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openParenthesis)); if ($numberOfArguments !== $count) { continue; diff --git a/src/Fixer/ArrayNotation/ArraySyntaxFixer.php b/src/Fixer/ArrayNotation/ArraySyntaxFixer.php index a7b0b20f6e3..4ce10b7192f 100644 --- a/src/Fixer/ArrayNotation/ArraySyntaxFixer.php +++ b/src/Fixer/ArrayNotation/ArraySyntaxFixer.php @@ -105,7 +105,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn private function fixToLongArraySyntax(Tokens $tokens, int $index): void { - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $index); $tokens[$index] = new Token('('); $tokens[$closeIndex] = new Token(')'); @@ -116,7 +116,7 @@ private function fixToLongArraySyntax(Tokens $tokens, int $index): void private function fixToShortArraySyntax(Tokens $tokens, int $index): void { $openIndex = $tokens->getNextTokenOfKind($index, ['(']); - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openIndex); $tokens[$openIndex] = new Token([CT::T_ARRAY_SQUARE_BRACE_OPEN, '[']); $tokens[$closeIndex] = new Token([CT::T_ARRAY_SQUARE_BRACE_CLOSE, ']']); diff --git a/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php b/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php index f2ff389dff3..1971495c0e4 100644 --- a/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php +++ b/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php @@ -83,10 +83,10 @@ private function fixSpacing(int $index, Tokens $tokens): void { if ($tokens[$index]->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) { $startIndex = $index; - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $startIndex); } else { $startIndex = $tokens->getNextTokenOfKind($index, ['(']); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startIndex); } for ($i = $endIndex - 1; $i > $startIndex; --$i) { @@ -109,11 +109,11 @@ private function fixSpacing(int $index, Tokens $tokens): void private function skipNonArrayElements(int $index, Tokens $tokens): int { if ($tokens[$index]->equals('}')) { - return $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + return $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $index); } if ($tokens[$index]->equals(')')) { - $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $startIndex = $tokens->getPrevMeaningfulToken($startIndex); if (!$tokens[$startIndex]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) { return $startIndex; diff --git a/src/Fixer/ArrayNotation/ReturnToYieldFromFixer.php b/src/Fixer/ArrayNotation/ReturnToYieldFromFixer.php index 4b130a27828..0b87f8349c1 100644 --- a/src/Fixer/ArrayNotation/ReturnToYieldFromFixer.php +++ b/src/Fixer/ArrayNotation/ReturnToYieldFromFixer.php @@ -73,10 +73,10 @@ private function shouldBeFixed(Tokens $tokens, int $returnIndex): bool } if ($tokens[$arrayStartIndex]->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) { - $arrayEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $arrayStartIndex); + $arrayEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $arrayStartIndex); } else { $arrayOpenParenthesisIndex = $tokens->getNextTokenOfKind($arrayStartIndex, ['(']); - $arrayEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $arrayOpenParenthesisIndex); + $arrayEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $arrayOpenParenthesisIndex); } $functionEndIndex = $arrayEndIndex; @@ -87,7 +87,7 @@ private function shouldBeFixed(Tokens $tokens, int $returnIndex): bool return false; } - $functionStartIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $functionEndIndex); + $functionStartIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $functionEndIndex); $returnTypeIndex = $tokens->getPrevMeaningfulToken($functionStartIndex); if (!$tokens[$returnTypeIndex]->isGivenKind(T_STRING)) { diff --git a/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php b/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php index 775e9125917..b6d3f658491 100644 --- a/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php +++ b/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php @@ -57,11 +57,11 @@ private static function fixArray(Tokens $tokens, int $index): void if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) { $startIndex = $tokens->getNextMeaningfulToken($startIndex); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startIndex); } elseif ($tokens[$startIndex]->isGivenKind(CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN)) { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_DESTRUCTURING_SQUARE_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_DESTRUCTURING_BRACKET, $startIndex); } else { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $startIndex); } $nextIndex = $startIndex + 1; diff --git a/src/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixer.php b/src/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixer.php index a9c7d051637..8aa6b0c1885 100644 --- a/src/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixer.php +++ b/src/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixer.php @@ -69,10 +69,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ($tokens[$index]->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) { $startIndex = $index; - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $startIndex); } else { $startIndex = $tokens->getNextTokenOfKind($index, ['(']); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startIndex); } for ($i = $endIndex - 1; $i > $startIndex; --$i) { @@ -106,11 +106,11 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void private function skipNonArrayElements(int $index, Tokens $tokens): int { if ($tokens[$index]->equals('}')) { - return $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + return $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $index); } if ($tokens[$index]->equals(')')) { - $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $startIndex = $tokens->getPrevMeaningfulToken($startIndex); if (!$tokens[$startIndex]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) { return $startIndex; diff --git a/src/Fixer/ArrayNotation/YieldFromArrayToYieldsFixer.php b/src/Fixer/ArrayNotation/YieldFromArrayToYieldsFixer.php index 7df614fcd61..1838485b1b3 100644 --- a/src/Fixer/ArrayNotation/YieldFromArrayToYieldsFixer.php +++ b/src/Fixer/ArrayNotation/YieldFromArrayToYieldsFixer.php @@ -142,10 +142,10 @@ private function getYieldsFromToUnpack(Tokens $tokens): iterable if ($tokens[$arrayStartIndex]->isGivenKind(T_ARRAY)) { $startIndex = $tokens->getNextTokenOfKind($arrayStartIndex, ['(']); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startIndex); } else { $startIndex = $arrayStartIndex; - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $startIndex); } // is there empty "yield from []" ? diff --git a/src/Fixer/AttributeNotation/AttributeEmptyParenthesesFixer.php b/src/Fixer/AttributeNotation/AttributeEmptyParenthesesFixer.php index cba0604640e..1544d2d907d 100644 --- a/src/Fixer/AttributeNotation/AttributeEmptyParenthesesFixer.php +++ b/src/Fixer/AttributeNotation/AttributeEmptyParenthesesFixer.php @@ -80,7 +80,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // Find closing parentheses, we need to do this in case there's a comma inside the parentheses if ($tokens[$nextIndex]->equals('(')) { - $nextIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex); + $nextIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $nextIndex); $nextIndex = $tokens->getNextTokenOfKind($nextIndex, [',', [CT::T_ATTRIBUTE_CLOSE]]); } diff --git a/src/Fixer/Basic/CurlyBracesPositionFixer.php b/src/Fixer/Basic/CurlyBracesPositionFixer.php index 3f36f84cd8c..1c385c28332 100644 --- a/src/Fixer/Basic/CurlyBracesPositionFixer.php +++ b/src/Fixer/Basic/CurlyBracesPositionFixer.php @@ -196,7 +196,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - $closeBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openBraceIndex); + $closeBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $openBraceIndex); $addNewlinesInsideBraces = true; if ($allowSingleLine || $allowSingleLineIfEmpty || $index < $allowSingleLineUntil) { @@ -382,7 +382,7 @@ private function findParenthesisEnd(Tokens $tokens, int $structureTokenIndex): i return $structureTokenIndex; } - return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex); + return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $nextIndex); } private function isFollowedByNewLine(Tokens $tokens, int $index): bool diff --git a/src/Fixer/Basic/NoMultipleStatementsPerLineFixer.php b/src/Fixer/Basic/NoMultipleStatementsPerLineFixer.php index d5c0b149855..4bf07d4995f 100644 --- a/src/Fixer/Basic/NoMultipleStatementsPerLineFixer.php +++ b/src/Fixer/Basic/NoMultipleStatementsPerLineFixer.php @@ -59,7 +59,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void for ($index = 1, $max = \count($tokens) - 1; $index < $max; ++$index) { if ($tokens[$index]->isGivenKind(T_FOR)) { $index = $tokens->findBlockEnd( - Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + Tokens::BLOCK_TYPE_PARENTHESIS, $tokens->getNextTokenOfKind($index, ['(']) ); diff --git a/src/Fixer/Basic/NoTrailingCommaInSinglelineFixer.php b/src/Fixer/Basic/NoTrailingCommaInSinglelineFixer.php index 610299b3fd3..340b0a1c5f7 100644 --- a/src/Fixer/Basic/NoTrailingCommaInSinglelineFixer.php +++ b/src/Fixer/Basic/NoTrailingCommaInSinglelineFixer.php @@ -139,8 +139,8 @@ private function shouldBeCleared(Tokens $tokens, int $openIndex): bool ( Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE === $block['type'] || Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE === $block['type'] - || Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE === $block['type'] - || Tokens::BLOCK_TYPE_PARENTHESIS_BRACE === $block['type'] + || Tokens::BLOCK_TYPE_INDEX_BRACKET === $block['type'] + || Tokens::BLOCK_TYPE_PARENTHESIS === $block['type'] ) && \in_array('arguments', $elements, true); } diff --git a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php index acc7bb323cb..f34a0222113 100644 --- a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php +++ b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php @@ -488,7 +488,7 @@ private function getElementsByClass(Tokens $tokens): \Generator $classIndex = $element['classIndex']; $classOpen = $tokens->getNextTokenOfKind($classIndex, ['{']); - $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpen); + $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $classOpen); $class = [ 'index' => $classIndex, 'open' => $classOpen, @@ -542,7 +542,7 @@ private function getLastTokenIndexOfClassElement(Tokens $tokens, array $class, a if (true === $attributes['abstract']) { $elementEndIndex = $tokens->getNextTokenOfKind($element['index'], [';']); } else { - $elementEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tokens->getNextTokenOfKind($element['index'], ['{'])); + $elementEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $tokens->getNextTokenOfKind($element['index'], ['{'])); } } elseif ('trait_import' === $element['type']) { $elementEndIndex = $element['index']; @@ -552,7 +552,7 @@ private function getLastTokenIndexOfClassElement(Tokens $tokens, array $class, a } while ($tokens[$elementEndIndex]->isGivenKind([T_STRING, T_NS_SEPARATOR]) || $tokens[$elementEndIndex]->equals(',')); if (!$tokens[$elementEndIndex]->equals(';')) { - $elementEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tokens->getNextTokenOfKind($element['index'], ['{'])); + $elementEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $tokens->getNextTokenOfKind($element['index'], ['{'])); } } else { // 'const', 'property', enum-'case', or 'method' of an interface $elementEndIndex = $tokens->getNextTokenOfKind($element['index'], [';']); diff --git a/src/Fixer/ClassNotation/ClassDefinitionFixer.php b/src/Fixer/ClassNotation/ClassDefinitionFixer.php index b0e226e4b91..9aa530a9a45 100644 --- a/src/Fixer/ClassNotation/ClassDefinitionFixer.php +++ b/src/Fixer/ClassNotation/ClassDefinitionFixer.php @@ -197,7 +197,7 @@ private function fixClassyDefinition(Tokens $tokens, int $classyIndex): void } if ($tokens[$end]->equals(')')) { // skip constructor arguments of anonymous class - $end = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $end); + $end = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $end); } } diff --git a/src/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixer.php b/src/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixer.php index ed9a7ac7a57..78f95a0fc6c 100644 --- a/src/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixer.php +++ b/src/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixer.php @@ -90,7 +90,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $classOpen = $tokens->getNextTokenOfKind($classIndex, ['{']); - $classClose = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpen); + $classClose = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $classOpen); $this->fixClass($tokens, $classOpen, $classClose); } @@ -101,7 +101,7 @@ private function fixClass(Tokens $tokens, int $classOpenIndex, int $classCloseIn for ($index = $classCloseIndex - 1; $index > $classOpenIndex; --$index) { // skip method contents if ($tokens[$index]->equals('}')) { - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $index); continue; } diff --git a/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php b/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php index be59a15eaba..8e40dcc2739 100644 --- a/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php +++ b/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php @@ -97,7 +97,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } // the index points to the { of a block-namespace - $nspEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nspIndex); + $nspEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $nspIndex); if ($index < $nspEnd) { // the class is inside a block namespace, skip other classes that might be in it @@ -116,7 +116,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $classNameIndex = $tokens->getNextMeaningfulToken($index); $className = $tokens[$classNameIndex]->getContent(); $classStart = $tokens->getNextTokenOfKind($classNameIndex, ['{']); - $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classStart); + $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $classStart); $this->fixConstructor($tokens, $className, $classStart, $classEnd); $this->fixParent($tokens, $classStart, $classEnd); @@ -394,7 +394,7 @@ private function findFunction(Tokens $tokens, string $name, int $startIndex, int } else { // find method body start and the end of the function definition $bodyStart = $tokens->getNextTokenOfKind($function[2], ['{']); - $funcEnd = null !== $bodyStart ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $bodyStart) : null; + $funcEnd = null !== $bodyStart ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $bodyStart) : null; } return [ diff --git a/src/Fixer/ClassNotation/OrderedClassElementsFixer.php b/src/Fixer/ClassNotation/OrderedClassElementsFixer.php index 4337889c202..9c2a4a73931 100644 --- a/src/Fixer/ClassNotation/OrderedClassElementsFixer.php +++ b/src/Fixer/ClassNotation/OrderedClassElementsFixer.php @@ -464,7 +464,7 @@ private function findElementEnd(Tokens $tokens, int $index): int $index = $tokens->getNextTokenOfKind($index, ['{', ';']); if ($tokens[$index]->equals('{')) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); } for (++$index; $tokens[$index]->isWhitespace(" \t") || $tokens[$index]->isComment(); ++$index); diff --git a/src/Fixer/ClassNotation/OrderedTraitsFixer.php b/src/Fixer/ClassNotation/OrderedTraitsFixer.php index a46689b3db6..474cc238f2b 100644 --- a/src/Fixer/ClassNotation/OrderedTraitsFixer.php +++ b/src/Fixer/ClassNotation/OrderedTraitsFixer.php @@ -100,7 +100,7 @@ private function findUseStatementsGroups(Tokens $tokens): iterable $endIndex = $tokens->getNextTokenOfKind($index, [';', '{']); if ($tokens[$endIndex]->equals('{')) { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $endIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $endIndex); } $use = []; @@ -154,7 +154,7 @@ private function sortMultipleTraitsInStatement(Tokens $use): void } if ($token->equals('{')) { - $index = $use->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $use->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); } } diff --git a/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php b/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php index 168bbb3b6c6..952d35df689 100644 --- a/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php +++ b/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php @@ -162,7 +162,7 @@ private function isClassCandidate(Tokens $tokens, int $classIndex): bool } $classOpenIndex = $tokens->getNextTokenOfKind($classNameIndex, ['{']); - $classCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpenIndex); + $classCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $classOpenIndex); $useIndex = $tokens->getNextTokenOfKind($classOpenIndex, [[CT::T_USE_TRAIT]]); return null === $useIndex || $useIndex > $classCloseIndex; diff --git a/src/Fixer/ClassNotation/SelfAccessorFixer.php b/src/Fixer/ClassNotation/SelfAccessorFixer.php index 0af1d3eaa41..b98d6b1e5a8 100644 --- a/src/Fixer/ClassNotation/SelfAccessorFixer.php +++ b/src/Fixer/ClassNotation/SelfAccessorFixer.php @@ -86,7 +86,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $nameIndex = $tokens->getNextTokenOfKind($index, [[T_STRING]]); $startIndex = $tokens->getNextTokenOfKind($nameIndex, ['{']); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $startIndex); $name = $tokens[$nameIndex]->getContent(); @@ -115,7 +115,7 @@ private function replaceNameOccurrences(Tokens $tokens, string $namespace, strin // skip anonymous classes if ($token->isGivenKind(T_CLASS) && $tokensAnalyzer->isAnonymousClass($i)) { $i = $tokens->getNextTokenOfKind($i, ['{']); - $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $i); + $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $i); continue; } diff --git a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php index 2eed24643c7..5848a475213 100644 --- a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php +++ b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php @@ -120,9 +120,9 @@ private function fixElement(Tokens $tokens, string $type, int $index): void if ($tokensAnalyzer->isArray($repeatIndex)) { if ($repeatToken->isGivenKind(T_ARRAY)) { $repeatIndex = $tokens->getNextTokenOfKind($repeatIndex, ['(']); - $repeatIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $repeatIndex); + $repeatIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $repeatIndex); } else { - $repeatIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $repeatIndex); + $repeatIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $repeatIndex); } continue; @@ -163,13 +163,13 @@ private function expandElement(Tokens $tokens, string $type, int $startIndex, in $token = $tokens[$i]; if ($token->equals(')')) { - $i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $i); + $i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $i); continue; } if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) { - $i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $i); + $i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $i); continue; } diff --git a/src/Fixer/ControlStructure/ControlStructureBracesFixer.php b/src/Fixer/ControlStructure/ControlStructureBracesFixer.php index 0fd0d264a10..e273fb4cfce 100644 --- a/src/Fixer/ControlStructure/ControlStructureBracesFixer.php +++ b/src/Fixer/ControlStructure/ControlStructureBracesFixer.php @@ -78,7 +78,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ($tokenAfterParenthesis->isGivenKind([T_IF, T_FOR, T_FOREACH, T_SWITCH, T_WHILE])) { $tokenAfterParenthesisBlockEnd = $tokens->findBlockEnd( // go to ')' - Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + Tokens::BLOCK_TYPE_PARENTHESIS, $tokens->getNextMeaningfulToken($nextAfterParenthesisEndIndex) ); @@ -124,7 +124,7 @@ private function findParenthesisEnd(Tokens $tokens, int $structureTokenIndex): i return $structureTokenIndex; } - return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex); + return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $nextIndex); } private function findStatementEnd(Tokens $tokens, int $parenthesisEndIndex): int @@ -137,7 +137,7 @@ private function findStatementEnd(Tokens $tokens, int $parenthesisEndIndex): int $nextToken = $tokens[$nextIndex]; if ($nextToken->equals('{')) { - return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nextIndex); + return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $nextIndex); } if ($nextToken->isGivenKind($this->getControlTokens())) { @@ -174,7 +174,7 @@ private function findStatementEnd(Tokens $tokens, int $parenthesisEndIndex): int // if there is some block in statement (eg lambda function) we need to skip it if ($token->equals('{')) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); continue; } diff --git a/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php b/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php index a51fa779a44..b22e26809c5 100644 --- a/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php +++ b/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php @@ -123,7 +123,7 @@ private function fixControlContinuationBraces(Tokens $tokens): void if ($token->isGivenKind(T_WHILE)) { $prevIndex = $tokens->getPrevMeaningfulToken( - $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $prevIndex) + $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $prevIndex) ); if (!$tokens[$prevIndex]->isGivenKind(T_DO)) { diff --git a/src/Fixer/ControlStructure/ElseifFixer.php b/src/Fixer/ControlStructure/ElseifFixer.php index 19c810ec607..88856dd6b81 100644 --- a/src/Fixer/ControlStructure/ElseifFixer.php +++ b/src/Fixer/ControlStructure/ElseifFixer.php @@ -71,7 +71,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } // if next meaningful token is T_IF, but uses an alternative syntax - this is not the case for fixing neither - $conditionEndBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextMeaningfulToken($ifTokenIndex)); + $conditionEndBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $tokens->getNextMeaningfulToken($ifTokenIndex)); $afterConditionIndex = $tokens->getNextMeaningfulToken($conditionEndBraceIndex); if ($tokens[$afterConditionIndex]->equals(':')) { continue; diff --git a/src/Fixer/ControlStructure/EmptyLoopBodyFixer.php b/src/Fixer/ControlStructure/EmptyLoopBodyFixer.php index 54f804fed0e..4abb60bb612 100644 --- a/src/Fixer/ControlStructure/EmptyLoopBodyFixer.php +++ b/src/Fixer/ControlStructure/EmptyLoopBodyFixer.php @@ -106,7 +106,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void for ($index = $tokens->count() - 1; $index > 0; --$index) { if ($tokens[$index]->isGivenKind(self::TOKEN_LOOP_KINDS)) { $endIndex = $tokens->getNextTokenOfKind($index, ['(']); // proceed to open '(' - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $endIndex); // proceed to close ')' + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $endIndex); // proceed to close ')' $fixLoop($index, $endIndex); // fix loop if needs fixing } } diff --git a/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php b/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php index 6e3c81fca21..66102c66f03 100644 --- a/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php +++ b/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php @@ -104,7 +104,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void for ($index = $tokens->count() - 1; $index > 0; --$index) { if ($tokens[$index]->isGivenKind($candidateLoopKinds)) { $openIndex = $tokens->getNextTokenOfKind($index, ['(']); // proceed to open '(' - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); // proceed to close ')' + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openIndex); // proceed to close ')' $fixLoop($index, $openIndex, $endIndex); // fix loop if needed } } @@ -152,7 +152,7 @@ private static function getDoIndex(Tokens $tokens, int $index): ?int return null; } - $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $endIndex); + $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $endIndex); $index = $tokens->getPrevMeaningfulToken($startIndex); return null === $index || !$tokens[$index]->isGivenKind(T_DO) ? null : $index; diff --git a/src/Fixer/ControlStructure/IncludeFixer.php b/src/Fixer/ControlStructure/IncludeFixer.php index 6ad13603834..e91f9abcf12 100644 --- a/src/Fixer/ControlStructure/IncludeFixer.php +++ b/src/Fixer/ControlStructure/IncludeFixer.php @@ -119,7 +119,7 @@ private function findIncludies(Tokens $tokens): array $braceOpenIndex = $tokens->getNextMeaningfulToken($index); if ($tokens[$braceOpenIndex]->equals('(')) { - $braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $braceOpenIndex); + $braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $braceOpenIndex); $includy['braces'] = [ 'open' => $braceOpenIndex, diff --git a/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php b/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php index e994ad929cf..42278c84801 100644 --- a/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php +++ b/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php @@ -87,7 +87,7 @@ private function findParenthesisEnd(Tokens $tokens, int $structureTokenIndex): i $nextToken = $tokens[$nextIndex]; return $nextToken->equals('(') - ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex) + ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $nextIndex) : $structureTokenIndex; // return if next token is not opening parenthesis } @@ -103,7 +103,7 @@ private function fixOpenCloseControls(int $index, Token $token, Tokens $tokens): { if ($token->isGivenKind([T_IF, T_FOREACH, T_WHILE, T_FOR, T_SWITCH, T_DECLARE])) { $openIndex = $tokens->getNextTokenOfKind($index, ['(']); - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openIndex); $afterParenthesisIndex = $tokens->getNextMeaningfulToken($closeIndex); $afterParenthesis = $tokens[$afterParenthesisIndex]; diff --git a/src/Fixer/ControlStructure/NoBreakCommentFixer.php b/src/Fixer/ControlStructure/NoBreakCommentFixer.php index b50a6c85563..4ef2bd80d2f 100644 --- a/src/Fixer/ControlStructure/NoBreakCommentFixer.php +++ b/src/Fixer/ControlStructure/NoBreakCommentFixer.php @@ -300,7 +300,7 @@ private function getStructureEnd(Tokens $tokens, int $position): int if ($initialToken->isGivenKind(self::getParenthesisedStructureKinds())) { $position = $tokens->findBlockEnd( - Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + Tokens::BLOCK_TYPE_PARENTHESIS, $tokens->getNextTokenOfKind($position, ['(']) ); } elseif ($initialToken->isGivenKind(T_CLASS)) { @@ -308,7 +308,7 @@ private function getStructureEnd(Tokens $tokens, int $position): int if ('(' === $tokens[$openParenthesisPosition]->getContent()) { $position = $tokens->findBlockEnd( - Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + Tokens::BLOCK_TYPE_PARENTHESIS, $openParenthesisPosition ); } @@ -320,11 +320,11 @@ private function getStructureEnd(Tokens $tokens, int $position): int return $tokens->getNextTokenOfKind($position, [';']); } - $position = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $position); + $position = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $position); if ($initialToken->isGivenKind(T_DO)) { $position = $tokens->findBlockEnd( - Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + Tokens::BLOCK_TYPE_PARENTHESIS, $tokens->getNextTokenOfKind($position, ['(']) ); diff --git a/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php b/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php index b0156c27a49..34ed7241810 100644 --- a/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php +++ b/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php @@ -40,13 +40,13 @@ final class NoUnneededControlParenthesesFixer extends AbstractFixer implements C */ private const BLOCK_TYPES = [ Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE, - Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, - Tokens::BLOCK_TYPE_CURLY_BRACE, - Tokens::BLOCK_TYPE_DESTRUCTURING_SQUARE_BRACE, + Tokens::BLOCK_TYPE_ARRAY_BRACKET, + Tokens::BLOCK_TYPE_BRACE, + Tokens::BLOCK_TYPE_DESTRUCTURING_BRACKET, Tokens::BLOCK_TYPE_DYNAMIC_PROP_BRACE, Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE, - Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, - Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + Tokens::BLOCK_TYPE_INDEX_BRACKET, + Tokens::BLOCK_TYPE_PARENTHESIS, ]; private const BEFORE_TYPES = [ @@ -191,9 +191,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void foreach ($tokens as $openIndex => $token) { if ($token->equals('(')) { - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openIndex); } elseif ($token->isGivenKind(CT::T_BRACE_CLASS_INSTANTIATION_OPEN)) { - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE_CLASS_INSTANTIATION, $openIndex); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_CLASS_INSTANTIATION, $openIndex); } else { continue; } @@ -480,7 +480,7 @@ private function isWrappedForElement(Tokens $tokens, int $beforeOpenIndex, int $ if ($tokens[$beforeOpenIndex]->equals('(') && $tokens[$afterCloseIndex]->equals(';')) { $forCandidateIndex = $tokens->getPrevMeaningfulToken($beforeOpenIndex); } elseif ($tokens[$afterCloseIndex]->equals(')') && $tokens[$beforeOpenIndex]->equals(';')) { - $forCandidateIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $afterCloseIndex); + $forCandidateIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $afterCloseIndex); $forCandidateIndex = $tokens->getPrevMeaningfulToken($forCandidateIndex); } @@ -516,7 +516,7 @@ private function isWrappedFnBody(Tokens $tokens, int $beforeOpenIndex, int $afte return false; } - $beforeOpenIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $beforeOpenIndex); + $beforeOpenIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $beforeOpenIndex); $beforeOpenIndex = $tokens->getPrevMeaningfulToken($beforeOpenIndex); if ($tokens[$beforeOpenIndex]->isGivenKind(CT::T_RETURN_REF)) { @@ -729,7 +729,7 @@ private function removeBrace(Tokens $tokens, int $index, bool $needsSpace): void private function closeCurlyBelongsToDynamicElement(Tokens $tokens, int $beforeOpenIndex): bool { - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $beforeOpenIndex); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $beforeOpenIndex); $index = $tokens->getPrevMeaningfulToken($index); if ($tokens[$index]->isGivenKind(T_DOUBLE_COLON)) { diff --git a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php index fbe15ee7bb2..759b0426c52 100644 --- a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php +++ b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php @@ -75,7 +75,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { foreach ($this->findCurlyBraceOpen($tokens) as $index) { if ($this->isOverComplete($tokens, $index)) { - $this->clearOverCompleteBraces($tokens, $index, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index)); + $this->clearOverCompleteBraces($tokens, $index, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index)); } } @@ -142,7 +142,7 @@ private function clearIfIsOverCompleteNamespaceBlock(Tokens $tokens): void return; // `;` } - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); $afterCloseIndex = $tokens->getNextMeaningfulToken($closeIndex); if (null !== $afterCloseIndex && (!$tokens[$afterCloseIndex]->isGivenKind(T_CLOSE_TAG) || null !== $tokens->getNextMeaningfulToken($afterCloseIndex))) { diff --git a/src/Fixer/ControlStructure/NoUselessElseFixer.php b/src/Fixer/ControlStructure/NoUselessElseFixer.php index 0542d348ad7..039c65b40f5 100644 --- a/src/Fixer/ControlStructure/NoUselessElseFixer.php +++ b/src/Fixer/ControlStructure/NoUselessElseFixer.php @@ -83,7 +83,7 @@ private function fixEmptyElse(Tokens $tokens, int $index): void $next = $tokens->getNextMeaningfulToken($index); if ($tokens[$next]->equals('{')) { - $close = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $next); + $close = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $next); if (1 === $close - $next) { // '{}' $this->clearElse($tokens, $index); } elseif ($tokens->getNextMeaningfulToken($next) === $close) { // '{/**/}' @@ -114,7 +114,7 @@ private function clearElse(Tokens $tokens, int $index): void return; } - $tokens->clearTokenAndMergeSurroundingWhitespace($tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $next)); + $tokens->clearTokenAndMergeSurroundingWhitespace($tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $next)); $tokens->clearTokenAndMergeSurroundingWhitespace($next); } } diff --git a/src/Fixer/ControlStructure/SimplifiedIfReturnFixer.php b/src/Fixer/ControlStructure/SimplifiedIfReturnFixer.php index 6c3a0c2c385..c13ad4f366b 100644 --- a/src/Fixer/ControlStructure/SimplifiedIfReturnFixer.php +++ b/src/Fixer/ControlStructure/SimplifiedIfReturnFixer.php @@ -96,7 +96,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $startParenthesisIndex = $tokens->getNextTokenOfKind($ifIndex, ['(']); - $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex); + $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startParenthesisIndex); $firstCandidateIndex = $tokens->getNextMeaningfulToken($endParenthesisIndex); foreach ($this->sequences as $sequenceSpec) { diff --git a/src/Fixer/ControlStructure/SwitchContinueToBreakFixer.php b/src/Fixer/ControlStructure/SwitchContinueToBreakFixer.php index 23b523a8c39..5a921fec5bc 100644 --- a/src/Fixer/ControlStructure/SwitchContinueToBreakFixer.php +++ b/src/Fixer/ControlStructure/SwitchContinueToBreakFixer.php @@ -131,7 +131,7 @@ private function fixInSwitch(Tokens $tokens, int $switchIndex, int $depth): int $openIndex = $tokens->getNextTokenOfKind($switchIndex, ['{']); // figure out where the switch ends - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openIndex); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $openIndex); for ($index = $openIndex + 1; $index < $closeIndex; ++$index) { $index = $this->doFix($tokens, $index, $depth, true); diff --git a/src/Fixer/ControlStructure/YodaStyleFixer.php b/src/Fixer/ControlStructure/YodaStyleFixer.php index 0a2674652d2..e58c1d2a181 100644 --- a/src/Fixer/ControlStructure/YodaStyleFixer.php +++ b/src/Fixer/ControlStructure/YodaStyleFixer.php @@ -243,7 +243,7 @@ private function findComparisonStart(Tokens $tokens, int $index): int if ( $block['isStart'] - || ($nonBlockFound && Tokens::BLOCK_TYPE_CURLY_BRACE === $block['type']) // closing of structure not related to the comparison + || ($nonBlockFound && Tokens::BLOCK_TYPE_BRACE === $block['type']) // closing of structure not related to the comparison ) { break; } @@ -531,7 +531,7 @@ private function isVariable(Tokens $tokens, int $start, int $end, bool $strict): // handle multiple braces around statement ((($a === 1))) while ( $tokens[$index]->equals('(') - && $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index) === $end + && $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index) === $end ) { $index = $tokens->getNextMeaningfulToken($index); $end = $tokens->getPrevMeaningfulToken($end); @@ -594,7 +594,7 @@ private function isVariable(Tokens $tokens, int $start, int $end, bool $strict): && $next->equalsAny(['[', [CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN, '{']]) ) { $index = $tokens->findBlockEnd( - $next->equals('[') ? Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE : Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE, + $next->equals('[') ? Tokens::BLOCK_TYPE_INDEX_BRACKET : Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE, $nextIndex ); diff --git a/src/Fixer/FunctionNotation/DateTimeCreateFromFormatCallFixer.php b/src/Fixer/FunctionNotation/DateTimeCreateFromFormatCallFixer.php index 5c72fcf2fb1..66dc62f07b0 100644 --- a/src/Fixer/FunctionNotation/DateTimeCreateFromFormatCallFixer.php +++ b/src/Fixer/FunctionNotation/DateTimeCreateFromFormatCallFixer.php @@ -110,7 +110,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $openIndex = $tokens->getNextTokenOfKind($functionNameIndex, ['(']); - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openIndex); $argumentIndex = $this->getFirstArgumentTokenIndex($tokens, $argumentsAnalyzer->getArguments($tokens, $openIndex, $closeIndex)); diff --git a/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php b/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php index 8e63c816abc..6ea88c05f53 100644 --- a/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php +++ b/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php @@ -118,7 +118,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex); + $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startParenthesisIndex); if (false === $this->configuration['trailing_comma_single_line'] && !$tokens->isPartialCodeMultiline($index, $endParenthesisIndex) @@ -154,7 +154,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $tokens->ensureWhitespaceAtIndex($afterParenthesisIndex + 1, 0, ' '); $useStartParenthesisIndex = $tokens->getNextTokenOfKind($afterParenthesisIndex, ['(']); - $useEndParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $useStartParenthesisIndex); + $useEndParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $useStartParenthesisIndex); if (false === $this->configuration['trailing_comma_single_line'] && !$tokens->isPartialCodeMultiline($index, $useEndParenthesisIndex) diff --git a/src/Fixer/FunctionNotation/ImplodeCallFixer.php b/src/Fixer/FunctionNotation/ImplodeCallFixer.php index 49d728ef0a4..a8dcb13b974 100644 --- a/src/Fixer/FunctionNotation/ImplodeCallFixer.php +++ b/src/Fixer/FunctionNotation/ImplodeCallFixer.php @@ -126,7 +126,7 @@ private function getArgumentIndices(Tokens $tokens, int $functionNameIndex): arr $argumentsAnalyzer = new ArgumentsAnalyzer(); $openParenthesis = $tokens->getNextTokenOfKind($functionNameIndex, ['(']); - $closeParenthesis = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesis); + $closeParenthesis = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openParenthesis); $indices = []; diff --git a/src/Fixer/FunctionNotation/LambdaNotUsedImportFixer.php b/src/Fixer/FunctionNotation/LambdaNotUsedImportFixer.php index 48155ceca16..72c8d56807d 100644 --- a/src/Fixer/FunctionNotation/LambdaNotUsedImportFixer.php +++ b/src/Fixer/FunctionNotation/LambdaNotUsedImportFixer.php @@ -82,7 +82,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void private function fixLambda(Tokens $tokens, int $lambdaUseIndex): void { $lambdaUseOpenBraceIndex = $tokens->getNextTokenOfKind($lambdaUseIndex, ['(']); - $lambdaUseCloseBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $lambdaUseOpenBraceIndex); + $lambdaUseCloseBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $lambdaUseOpenBraceIndex); $arguments = $this->argumentsAnalyzer->getArguments($tokens, $lambdaUseOpenBraceIndex, $lambdaUseCloseBraceIndex); $imports = $this->filterArguments($tokens, $arguments); @@ -189,7 +189,7 @@ private function findNotUsedLambdaImports(Tokens $tokens, array $imports, int $l $index = $tokens->getNextTokenOfKind($index, ['(', '{']); if ($tokens[$index]->equals('(')) { - $closeBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $closeBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $arguments = $this->argumentsAnalyzer->getArguments($tokens, $index, $closeBraceIndex); $imports = $this->countImportsUsedAsArgument($tokens, $imports, $arguments); @@ -198,7 +198,7 @@ private function findNotUsedLambdaImports(Tokens $tokens, array $imports, int $l } // skip body - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); continue; } @@ -206,7 +206,7 @@ private function findNotUsedLambdaImports(Tokens $tokens, array $imports, int $l if ($token->isGivenKind(T_FUNCTION)) { // check if used as argument $lambdaUseOpenBraceIndex = $tokens->getNextTokenOfKind($index, ['(']); - $lambdaUseCloseBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $lambdaUseOpenBraceIndex); + $lambdaUseCloseBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $lambdaUseOpenBraceIndex); $arguments = $this->argumentsAnalyzer->getArguments($tokens, $lambdaUseOpenBraceIndex, $lambdaUseCloseBraceIndex); $imports = $this->countImportsUsedAsArgument($tokens, $imports, $arguments); @@ -216,7 +216,7 @@ private function findNotUsedLambdaImports(Tokens $tokens, array $imports, int $l if ($tokens[$index]->isGivenKind(CT::T_USE_LAMBDA)) { $lambdaUseOpenBraceIndex = $tokens->getNextTokenOfKind($index, ['(']); - $lambdaUseCloseBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $lambdaUseOpenBraceIndex); + $lambdaUseCloseBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $lambdaUseOpenBraceIndex); $arguments = $this->argumentsAnalyzer->getArguments($tokens, $lambdaUseOpenBraceIndex, $lambdaUseCloseBraceIndex); $imports = $this->countImportsUsedAsArgument($tokens, $imports, $arguments); @@ -225,7 +225,7 @@ private function findNotUsedLambdaImports(Tokens $tokens, array $imports, int $l } // skip body - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); continue; } @@ -267,7 +267,7 @@ private function getLambdaUseIndex(Tokens $tokens, int $index) $lambdaUseIndex = $tokens->getNextMeaningfulToken($lambdaUseIndex); } - $lambdaUseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $lambdaUseIndex); // we are @ ')' after this + $lambdaUseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $lambdaUseIndex); // we are @ ')' after this $lambdaUseIndex = $tokens->getNextMeaningfulToken($lambdaUseIndex); if (!$tokens[$lambdaUseIndex]->isGivenKind(CT::T_USE_LAMBDA)) { diff --git a/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php b/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php index 5f47784e7a9..4e9b606b56a 100644 --- a/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php +++ b/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php @@ -201,7 +201,7 @@ private function fixFunction(Tokens $tokens, int $startFunctionIndex): bool { $isMultiline = false; - $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startFunctionIndex); + $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startFunctionIndex); $firstWhitespaceIndex = $this->findWhitespaceIndexAfterParenthesis($tokens, $startFunctionIndex, $endFunctionIndex); $lastWhitespaceIndex = $this->findWhitespaceIndexAfterParenthesis($tokens, $endFunctionIndex, $startFunctionIndex); @@ -227,19 +227,19 @@ private function fixFunction(Tokens $tokens, int $startFunctionIndex): bool $token = $tokens[$index]; if ($token->equals(')')) { - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $index); continue; } if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) { - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $index); continue; } if ($token->equals('}')) { - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $index); continue; } @@ -320,7 +320,7 @@ private function ensureFunctionFullyMultiline(Tokens $tokens, int $startFunction } $indentation = $existingIndentation.$this->whitespacesConfig->getIndent(); - $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startFunctionIndex); + $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startFunctionIndex); $wasWhitespaceBeforeEndFunctionAddedAsNewToken = $tokens->ensureWhitespaceAtIndex( $tokens[$endFunctionIndex - 1]->isWhitespace() ? $endFunctionIndex - 1 : $endFunctionIndex, @@ -337,20 +337,20 @@ private function ensureFunctionFullyMultiline(Tokens $tokens, int $startFunction // skip nested method calls and arrays if ($token->equals(')')) { - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $index); continue; } // skip nested arrays if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) { - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $index); continue; } if ($token->equals('}')) { - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $index); continue; } diff --git a/src/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixer.php b/src/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixer.php index e435b782a81..fe829d9b766 100644 --- a/src/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixer.php +++ b/src/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixer.php @@ -69,7 +69,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $lastTokenIndex = $tokens->getPrevNonWhitespace($index); // check for ternary operator - $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $nextNonWhiteSpace = $tokens->getNextMeaningfulToken($endParenthesisIndex); if ( null !== $nextNonWhiteSpace @@ -92,8 +92,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ( Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE === $block['type'] || Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE === $block['type'] - || Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE === $block['type'] - || Tokens::BLOCK_TYPE_PARENTHESIS_BRACE === $block['type'] + || Tokens::BLOCK_TYPE_INDEX_BRACKET === $block['type'] + || Tokens::BLOCK_TYPE_PARENTHESIS === $block['type'] ) { $this->fixFunctionCall($tokens, $index); } diff --git a/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php b/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php index 108901da321..6ad2f23dd01 100644 --- a/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php +++ b/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php @@ -74,7 +74,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $startIndex = $tokens->getNextTokenOfKind($i, ['(']); - $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex); + $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startIndex); $this->fixFunctionDefinition($tokens, $startIndex, $i); } diff --git a/src/Fixer/FunctionNotation/NoUselessSprintfFixer.php b/src/Fixer/FunctionNotation/NoUselessSprintfFixer.php index 125bbab6e8b..eac942e4fab 100644 --- a/src/Fixer/FunctionNotation/NoUselessSprintfFixer.php +++ b/src/Fixer/FunctionNotation/NoUselessSprintfFixer.php @@ -82,7 +82,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesisIndex); + $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openParenthesisIndex); if (1 !== $argumentsAnalyzer->countArguments($tokens, $openParenthesisIndex, $closeParenthesisIndex)) { continue; diff --git a/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php index 8625236c805..819999be5f9 100644 --- a/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php @@ -156,7 +156,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void private function findCorrectVariable(Tokens $tokens, int $startIndex, Annotation $paramTypeAnnotation): ?int { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startIndex); for ($index = $startIndex + 1; $index < $endIndex; ++$index) { if (!$tokens[$index]->isGivenKind(T_VARIABLE)) { diff --git a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php index 1de553fa4c2..1b6474e5cfd 100644 --- a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php @@ -98,14 +98,14 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void private function fixClass(Tokens $tokens, int $index): void { $index = $tokens->getNextTokenOfKind($index, ['{']); - $classEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $classEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); for (; $index < $classEndIndex; ++$index) { if ($tokens[$index]->isGivenKind(T_FUNCTION)) { $index = $tokens->getNextTokenOfKind($index, ['{', ';']); if ($tokens[$index]->equals('{')) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); } continue; diff --git a/src/Fixer/FunctionNotation/RegularCallableCallFixer.php b/src/Fixer/FunctionNotation/RegularCallableCallFixer.php index 2bb372c346a..9be7baf567e 100644 --- a/src/Fixer/FunctionNotation/RegularCallableCallFixer.php +++ b/src/Fixer/FunctionNotation/RegularCallableCallFixer.php @@ -91,7 +91,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $openParenthesis = $tokens->getNextMeaningfulToken($index); - $closeParenthesis = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesis); + $closeParenthesis = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openParenthesis); $arguments = $argumentsAnalyzer->getArguments($tokens, $openParenthesis, $closeParenthesis); if (1 > \count($arguments)) { @@ -142,7 +142,7 @@ private function processCall(Tokens $tokens, int $index, array $arguments): void ) ) { $firstArgEndIndex = $tokens->findBlockEnd( - Tokens::BLOCK_TYPE_CURLY_BRACE, + Tokens::BLOCK_TYPE_BRACE, $tokens->getNextTokenOfKind($firstArgIndex, ['{']) ); @@ -179,7 +179,7 @@ private function processCall(Tokens $tokens, int $index, array $arguments): void $blockType = Tokens::detectBlockType($newCallTokens[$newCallIndex]); - if (null !== $blockType && (Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE === $blockType['type'] || Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE === $blockType['type'])) { + if (null !== $blockType && (Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE === $blockType['type'] || Tokens::BLOCK_TYPE_INDEX_BRACKET === $blockType['type'])) { $newCallIndex = $newCallTokens->findBlockStart($blockType['type'], $newCallIndex); continue; diff --git a/src/Fixer/FunctionNotation/SingleLineThrowFixer.php b/src/Fixer/FunctionNotation/SingleLineThrowFixer.php index 0b2a226769d..4fe034ab2d7 100644 --- a/src/Fixer/FunctionNotation/SingleLineThrowFixer.php +++ b/src/Fixer/FunctionNotation/SingleLineThrowFixer.php @@ -69,7 +69,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $blockType = Tokens::detectBlockType($tokens[$endCandidateIndex]); if (null !== $blockType) { - if (Tokens::BLOCK_TYPE_CURLY_BRACE === $blockType['type'] || !$blockType['isStart']) { + if (Tokens::BLOCK_TYPE_BRACE === $blockType['type'] || !$blockType['isStart']) { break; } diff --git a/src/Fixer/FunctionNotation/StaticLambdaFixer.php b/src/Fixer/FunctionNotation/StaticLambdaFixer.php index 7e010ab54c4..9f611de4857 100644 --- a/src/Fixer/FunctionNotation/StaticLambdaFixer.php +++ b/src/Fixer/FunctionNotation/StaticLambdaFixer.php @@ -62,13 +62,13 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $argumentsStartIndex = $tokens->getNextTokenOfKind($index, ['(']); - $argumentsEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $argumentsStartIndex); + $argumentsEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $argumentsStartIndex); // figure out where the lambda starts and ends if ($tokens[$index]->isGivenKind(T_FUNCTION)) { $lambdaOpenIndex = $tokens->getNextTokenOfKind($argumentsEndIndex, ['{']); - $lambdaEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $lambdaOpenIndex); + $lambdaEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $lambdaOpenIndex); } else { // T_FN $lambdaOpenIndex = $tokens->getNextTokenOfKind($argumentsEndIndex, [[T_DOUBLE_ARROW]]); $lambdaEndIndex = $this->findExpressionEnd($tokens, $lambdaOpenIndex); diff --git a/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php b/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php index 5cafd0a3083..5e78491add5 100644 --- a/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php +++ b/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php @@ -87,7 +87,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $parametersStart = $tokens->getNextMeaningfulToken($parametersStart); } - $parametersEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $parametersStart); + $parametersEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $parametersStart); if ($this->isMultilined($tokens, $parametersStart, $parametersEnd)) { continue; diff --git a/src/Fixer/FunctionNotation/VoidReturnFixer.php b/src/Fixer/FunctionNotation/VoidReturnFixer.php index 65e8268dade..32ddf9354c8 100644 --- a/src/Fixer/FunctionNotation/VoidReturnFixer.php +++ b/src/Fixer/FunctionNotation/VoidReturnFixer.php @@ -109,7 +109,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $startIndex); if ($this->hasVoidReturn($tokens, $startIndex, $endIndex)) { $this->fixFunctionDefinition($tokens, $startIndex); @@ -180,7 +180,7 @@ private function hasVoidReturn(Tokens $tokens, int $startIndex, int $endIndex): || ($tokens[$i]->isGivenKind(T_FUNCTION) && $tokensAnalyzer->isLambda($i)) ) { $i = $tokens->getNextTokenOfKind($i, ['{']); - $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $i); + $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $i); continue; } diff --git a/src/Fixer/Import/GlobalNamespaceImportFixer.php b/src/Fixer/Import/GlobalNamespaceImportFixer.php index adda98289a0..3de06bbe8d1 100644 --- a/src/Fixer/Import/GlobalNamespaceImportFixer.php +++ b/src/Fixer/Import/GlobalNamespaceImportFixer.php @@ -177,7 +177,7 @@ private function importConstants(Tokens $tokens, array $useDeclarations): array if ($token->isClassy()) { $index = $tokens->getNextTokenOfKind($index, ['{']); - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); continue; } @@ -647,7 +647,7 @@ private function findFunctionDeclarations(Tokens $tokens, int $start, int $end): if ($token->isClassy()) { $classStart = $tokens->getNextTokenOfKind($index, ['{']); - $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classStart); + $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $classStart); for ($index = $classStart; $index <= $classEnd; ++$index) { if (!$tokens[$index]->isGivenKind(T_FUNCTION)) { @@ -662,7 +662,7 @@ private function findFunctionDeclarations(Tokens $tokens, int $start, int $end): continue; } - $methodEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $methodStart); + $methodEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $methodStart); foreach ($this->findFunctionDeclarations($tokens, $methodStart, $methodEnd) as $function) { yield $function; diff --git a/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php b/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php index 6ec6b753fba..de5e8549132 100644 --- a/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php +++ b/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php @@ -67,7 +67,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $tokensAddCount = $this->moveTokens( $tokens, $nextUnsetContentStart = $tokens->getNextTokenOfKind($index, ['(']), - $nextUnsetContentEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextUnsetContentStart), + $nextUnsetContentEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $nextUnsetContentStart), $previousUnsetBraceEnd - 1 ); @@ -134,7 +134,7 @@ private function getPreviousUnsetCall(Tokens $tokens, int $index) return $previousUnsetBraceEnd; } - $previousUnsetBraceStart = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $previousUnsetBraceEnd); + $previousUnsetBraceStart = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $previousUnsetBraceEnd); $previousUnset = $tokens->getPrevMeaningfulToken($previousUnsetBraceStart); if (null === $previousUnset) { return $index; diff --git a/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php b/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php index 76b70a20ca1..e7dc0818274 100644 --- a/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php +++ b/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php @@ -77,7 +77,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $openParenthesisIndex = $tokens->getNextMeaningfulToken($index); - $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesisIndex); + $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openParenthesisIndex); for ($i = $closeParenthesisIndex; $i > $openParenthesisIndex; --$i) { if ($tokens[$i]->equals('=')) { diff --git a/src/Fixer/LanguageConstruct/DeclareParenthesesFixer.php b/src/Fixer/LanguageConstruct/DeclareParenthesesFixer.php index e3879731018..6989e17eb0f 100644 --- a/src/Fixer/LanguageConstruct/DeclareParenthesesFixer.php +++ b/src/Fixer/LanguageConstruct/DeclareParenthesesFixer.php @@ -49,7 +49,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $startParenthesisIndex = $tokens->getNextTokenOfKind($index, ['(']); $tokens->removeTrailingWhitespace($startParenthesisIndex); - $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex); + $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startParenthesisIndex); $tokens->removeLeadingWhitespace($endParenthesisIndex); } } diff --git a/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php b/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php index 5cf4b8521db..6e35c122bf0 100644 --- a/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php +++ b/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php @@ -157,7 +157,7 @@ private function isDeprecationErrorCall(Tokens $tokens, int $index): bool return false; } - $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextTokenOfKind($index, [[T_STRING], '('])); + $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $tokens->getNextTokenOfKind($index, [[T_STRING], '('])); $prevIndex = $tokens->getPrevMeaningfulToken($endBraceIndex); if ($tokens[$prevIndex]->equals(',')) { diff --git a/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php b/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php index 7423504ff9a..9cb866abd45 100644 --- a/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php +++ b/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php @@ -230,7 +230,7 @@ private function fixGetClassCall( } $braceOpenIndex = $tokens->getNextMeaningfulToken($index); - $braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $braceOpenIndex); + $braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $braceOpenIndex); if ($braceCloseIndex === $tokens->getNextMeaningfulToken($braceOpenIndex)) { // no arguments passed if (isset($this->functionsFixMap['get_class'])) { diff --git a/src/Fixer/LanguageConstruct/GetClassToClassKeywordFixer.php b/src/Fixer/LanguageConstruct/GetClassToClassKeywordFixer.php index d5ceb526f37..a71d50ae70e 100644 --- a/src/Fixer/LanguageConstruct/GetClassToClassKeywordFixer.php +++ b/src/Fixer/LanguageConstruct/GetClassToClassKeywordFixer.php @@ -85,7 +85,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $braceOpenIndex = $tokens->getNextMeaningfulToken($index); - $braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $braceOpenIndex); + $braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $braceOpenIndex); if ($braceCloseIndex === $tokens->getNextMeaningfulToken($braceOpenIndex)) { continue; // get_class with no arguments diff --git a/src/Fixer/LanguageConstruct/IsNullFixer.php b/src/Fixer/LanguageConstruct/IsNullFixer.php index a99695d4faa..1cfa833b61a 100644 --- a/src/Fixer/LanguageConstruct/IsNullFixer.php +++ b/src/Fixer/LanguageConstruct/IsNullFixer.php @@ -112,7 +112,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } // before getting rind of `()` around a parameter, ensure it's not assignment/ternary invariant - $referenceEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $matches[1]); + $referenceEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $matches[1]); $isContainingDangerousConstructs = false; for ($paramTokenIndex = $matches[1]; $paramTokenIndex <= $referenceEnd; ++$paramTokenIndex) { diff --git a/src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php b/src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php index 15a151a15cf..4688a217aa1 100644 --- a/src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php +++ b/src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php @@ -91,7 +91,7 @@ private function getUnsetsInfo(Tokens $tokens, int $index): array $argumentsAnalyzer = new ArgumentsAnalyzer(); $unsetStart = $tokens->getNextTokenOfKind($index, ['(']); - $unsetEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $unsetStart); + $unsetEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $unsetStart); $isFirst = true; $unsets = []; diff --git a/src/Fixer/ListNotation/ListSyntaxFixer.php b/src/Fixer/ListNotation/ListSyntaxFixer.php index f7f06bca574..18db1ecda0f 100644 --- a/src/Fixer/ListNotation/ListSyntaxFixer.php +++ b/src/Fixer/ListNotation/ListSyntaxFixer.php @@ -120,7 +120,7 @@ private function fixToLongSyntax(Tokens $tokens, int $index): void private function fixToShortSyntax(Tokens $tokens, int $index): void { $openIndex = $tokens->getNextTokenOfKind($index, ['(']); - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openIndex); $tokens[$openIndex] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, '[']); $tokens[$closeIndex] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE, ']']); diff --git a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php index 67512104c3e..e43a45020d7 100644 --- a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php +++ b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php @@ -637,7 +637,7 @@ private function injectAlignmentPlaceholdersDefault(Tokens $tokens, int $startAt $index = $tokens->getNextTokenOfKind($index, ['{', ';', '(']); // We don't align `=` on multi-line definition of function parameters with default values if ($tokens[$index]->equals('(')) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); continue; } @@ -651,7 +651,7 @@ private function injectAlignmentPlaceholdersDefault(Tokens $tokens, int $startAt } if ($token->equals('{')) { - $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); $this->injectAlignmentPlaceholders($tokens, $index + 1, $until - 1, $tokenContent); $index = $until; @@ -659,7 +659,7 @@ private function injectAlignmentPlaceholdersDefault(Tokens $tokens, int $startAt } if ($token->equals('(')) { - $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $this->injectAlignmentPlaceholders($tokens, $index + 1, $until - 1, $tokenContent); $index = $until; @@ -667,13 +667,13 @@ private function injectAlignmentPlaceholdersDefault(Tokens $tokens, int $startAt } if ($token->equals('[')) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_BRACKET, $index); continue; } if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) { - $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index); + $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $index); $this->injectAlignmentPlaceholders($tokens, $index + 1, $until - 1, $tokenContent); $index = $until; @@ -725,7 +725,7 @@ private function injectAlignmentPlaceholdersForArrow(Tokens $tokens, int $startA if ($token->isGivenKind(T_ARRAY)) { // don't use "$tokens->isArray()" here, short arrays are handled in the next case $yieldFoundSinceLastPlaceholder = false; $from = $tokens->getNextMeaningfulToken($index); - $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $from); + $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $from); $index = $until; $this->injectArrayAlignmentPlaceholders($tokens, $from + 1, $until - 1); @@ -736,7 +736,7 @@ private function injectAlignmentPlaceholdersForArrow(Tokens $tokens, int $startA if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) { $yieldFoundSinceLastPlaceholder = false; $from = $index; - $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $from); + $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $from); $index = $until; $this->injectArrayAlignmentPlaceholders($tokens, $from + 1, $until - 1); @@ -799,7 +799,7 @@ private function injectAlignmentPlaceholdersForArrow(Tokens $tokens, int $startA } if ($token->equals('{')) { - $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); $this->injectArrayAlignmentPlaceholders($tokens, $index + 1, $until - 1); $index = $until; @@ -807,7 +807,7 @@ private function injectAlignmentPlaceholdersForArrow(Tokens $tokens, int $startA } if ($token->equals('(')) { - $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $this->injectArrayAlignmentPlaceholders($tokens, $index + 1, $until - 1); $index = $until; diff --git a/src/Fixer/Operator/TernaryToNullCoalescingFixer.php b/src/Fixer/Operator/TernaryToNullCoalescingFixer.php index 83cf9337de0..c10fa0774c4 100644 --- a/src/Fixer/Operator/TernaryToNullCoalescingFixer.php +++ b/src/Fixer/Operator/TernaryToNullCoalescingFixer.php @@ -74,7 +74,7 @@ private function fixIsset(Tokens $tokens, int $index): void } $startBraceIndex = $tokens->getNextTokenOfKind($index, ['(']); - $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startBraceIndex); + $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startBraceIndex); $ternaryQuestionMarkIndex = $tokens->getNextMeaningfulToken($endBraceIndex); diff --git a/src/Fixer/PhpUnit/PhpUnitDataProviderReturnTypeFixer.php b/src/Fixer/PhpUnit/PhpUnitDataProviderReturnTypeFixer.php index 4c077585d00..0b661d5ffbe 100644 --- a/src/Fixer/PhpUnit/PhpUnitDataProviderReturnTypeFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitDataProviderReturnTypeFixer.php @@ -88,7 +88,7 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en if (null === $typeAnalysis) { $argumentsStart = $tokens->getNextTokenOfKind($dataProviderAnalysis->getNameIndex(), ['(']); - $argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $argumentsStart); + $argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $argumentsStart); $tokens->insertAt( $argumentsEnd + 1, diff --git a/src/Fixer/PhpUnit/PhpUnitDataProviderStaticFixer.php b/src/Fixer/PhpUnit/PhpUnitDataProviderStaticFixer.php index 3d4786b7e0f..7c221f7adc2 100644 --- a/src/Fixer/PhpUnit/PhpUnitDataProviderStaticFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitDataProviderStaticFixer.php @@ -111,7 +111,7 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en foreach ($dataProviderAnalyzer->getDataProviders($tokens, $startIndex, $endIndex) as $dataProviderDefinitionIndex) { $methodStartIndex = $tokens->getNextTokenOfKind($dataProviderDefinitionIndex->getNameIndex(), ['{']); if (null !== $methodStartIndex) { - $methodEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $methodStartIndex); + $methodEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $methodStartIndex); if (!$this->configuration['force'] && null !== $tokens->findSequence([[T_VARIABLE, '$this']], $methodStartIndex, $methodEndIndex)) { continue; diff --git a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php index ed599f5f4f5..9551791a338 100644 --- a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php @@ -298,7 +298,7 @@ private function fixAssertTrueFalse(Tokens $tokens, ArgumentsAnalyzer $arguments return; } - $testCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $testOpenIndex); + $testCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $testOpenIndex); $assertCallCloseIndex = $tokens->getNextMeaningfulToken($testCloseIndex); if (!$tokens[$assertCallCloseIndex]->equalsAny([')', ','])) { @@ -495,7 +495,7 @@ private function fixAssertSameEquals(Tokens $tokens, array $assertCall): void return; } - $countCallCloseBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $countCallOpenBraceIndex); + $countCallCloseBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $countCallOpenBraceIndex); $afterCountCallCloseBraceIndex = $tokens->getNextMeaningfulToken($countCallCloseBraceIndex); if (!$tokens[$afterCountCallCloseBraceIndex]->equalsAny([')', ','])) { @@ -557,7 +557,7 @@ private function getPreviousAssertCall(Tokens $tokens, int $startIndex, int $end 'index' => $index, 'loweredName' => $loweredContent, 'openBraceIndex' => $openBraceIndex, - 'closeBraceIndex' => $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openBraceIndex), + 'closeBraceIndex' => $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openBraceIndex), ]; } } diff --git a/src/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixer.php b/src/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixer.php index b6e955ea45d..e5f949f9965 100644 --- a/src/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixer.php @@ -126,7 +126,7 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en } $openingBraceIndex = $tokens->getNextTokenOfKind($index, ['{']); - $closingBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openingBraceIndex); + $closingBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $openingBraceIndex); $anonymousClassIndices[$closingBraceIndex] = $openingBraceIndex; } diff --git a/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php b/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php index ca8464d285a..b0ed1a03de4 100644 --- a/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php @@ -199,7 +199,7 @@ private function applyPhpUnitClassFixWithObjectOperator(Tokens $tokens, int $sta } $openIndex = $tokens->getNextTokenOfKind($index, ['(']); - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openIndex); $commaIndex = $tokens->getPrevMeaningfulToken($closeIndex); if ($tokens[$commaIndex]->equals(',')) { $tokens->removeTrailingWhitespace($commaIndex); diff --git a/src/Fixer/PhpUnit/PhpUnitMockFixer.php b/src/Fixer/PhpUnit/PhpUnitMockFixer.php index a3d3484c674..986751db698 100644 --- a/src/Fixer/PhpUnit/PhpUnitMockFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitMockFixer.php @@ -101,7 +101,7 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en $tokens[$index] = new Token([T_STRING, 'createMock']); } elseif ($tokens[$index]->equals([T_STRING, 'getMock'], false)) { $openingParenthesis = $tokens->getNextMeaningfulToken($index); - $closingParenthesis = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openingParenthesis); + $closingParenthesis = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openingParenthesis); $argumentsCount = $argumentsAnalyzer->countArguments($tokens, $openingParenthesis, $closingParenthesis); diff --git a/src/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixer.php b/src/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixer.php index e429a7ae8da..e2989e1d73b 100644 --- a/src/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixer.php @@ -109,7 +109,7 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en continue; } - $closingBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openingBraceIndex); + $closingBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openingBraceIndex); $tokens[$functionToReplaceIndex] = new Token([T_STRING, self::RETURN_METHODS_MAP[strtolower($tokens[$functionToRemoveIndex]->getContent())]]); $tokens->clearTokenAndMergeSurroundingWhitespace($classReferenceIndex); diff --git a/src/Fixer/PhpUnit/PhpUnitStrictFixer.php b/src/Fixer/PhpUnit/PhpUnitStrictFixer.php index 4d5325661c5..274ee5f0f0c 100644 --- a/src/Fixer/PhpUnit/PhpUnitStrictFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitStrictFixer.php @@ -111,7 +111,7 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en $argumentsCount = $argumentsAnalyzer->countArguments( $tokens, $openingParenthesisIndex, - $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openingParenthesisIndex) + $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openingParenthesisIndex) ); if (2 === $argumentsCount || 3 === $argumentsCount) { diff --git a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php index 692389c8563..fafee5ef86c 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php @@ -476,7 +476,7 @@ private function findEndOfNextBlock(Tokens $tokens, int $index): int $nextIndex = $tokens->getNextTokenOfKind($index, [';', '{']); return $tokens[$nextIndex]->equals('{') - ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nextIndex) + ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $nextIndex) : $nextIndex; } } diff --git a/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php b/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php index c8b62882133..aa1de084762 100644 --- a/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php +++ b/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php @@ -137,7 +137,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ($token->isGivenKind($symbolKinds)) { $currentSymbol = $tokens[$tokens->getNextMeaningfulToken($index)]->getContent(); $currentSymbolEndIndex = $tokens->findBlockEnd( - Tokens::BLOCK_TYPE_CURLY_BRACE, + Tokens::BLOCK_TYPE_BRACE, $tokens->getNextTokenOfKind($index, ['{']), ); @@ -311,7 +311,7 @@ private function fixFunctionDocComment( $docBlock = new DocBlock($content); $openingParenthesisIndex = $tokens->getNextTokenOfKind($element['index'], ['(']); - $closingParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openingParenthesisIndex); + $closingParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openingParenthesisIndex); $argumentsInfo = $this->getArgumentsInfo( $tokens, diff --git a/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php b/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php index 908a4bc0bb0..024781acf64 100644 --- a/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php +++ b/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php @@ -138,7 +138,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $openIndex = $tokens->getNextTokenOfKind($index, ['(']); - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openIndex); $arguments = []; diff --git a/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php b/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php index 4174f2d93b2..71c84fd81e7 100644 --- a/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php +++ b/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php @@ -71,7 +71,7 @@ private function fixClassy(Tokens $tokens, int $index): int $classOpenIndex = $tokens->getNextTokenOfKind($index, ['{']); // figure out where the classy ends - $classEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpenIndex); + $classEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $classOpenIndex); // is classy extending or implementing some interface $extendingOrImplementing = $this->isExtendingOrImplementing($tokens, $index, $classOpenIndex); diff --git a/src/Fixer/Phpdoc/PhpdocParamOrderFixer.php b/src/Fixer/Phpdoc/PhpdocParamOrderFixer.php index fb3f41240d0..824ffe0477f 100644 --- a/src/Fixer/Phpdoc/PhpdocParamOrderFixer.php +++ b/src/Fixer/Phpdoc/PhpdocParamOrderFixer.php @@ -107,7 +107,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void */ private function getFunctionParamNames(Tokens $tokens, int $paramBlockStart): array { - $paramBlockEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $paramBlockStart); + $paramBlockEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $paramBlockStart); $paramNames = []; for ( diff --git a/src/Fixer/ReturnNotation/NoUselessReturnFixer.php b/src/Fixer/ReturnNotation/NoUselessReturnFixer.php index 1aac27c8a28..1342ff98f61 100644 --- a/src/Fixer/ReturnNotation/NoUselessReturnFixer.php +++ b/src/Fixer/ReturnNotation/NoUselessReturnFixer.php @@ -66,7 +66,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $index = $tokens->getNextTokenOfKind($index, [';', '{']); if ($tokens[$index]->equals('{')) { - $this->fixFunction($tokens, $index, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index)); + $this->fixFunction($tokens, $index, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index)); } } } diff --git a/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php b/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php index 291f9705d4d..df63304fa6a 100644 --- a/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php +++ b/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php @@ -73,7 +73,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - $functionCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $functionOpenIndex); + $functionCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $functionOpenIndex); $totalTokensAdded = 0; do { @@ -144,7 +144,7 @@ private function fixFunction(Tokens $tokens, int $functionIndex, int $functionOp continue; } - $nestedFunctionCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nestedFunctionOpenIndex); + $nestedFunctionCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $nestedFunctionOpenIndex); $tokensAdded = $this->fixFunction( $tokens, @@ -242,7 +242,7 @@ private function fixFunction(Tokens $tokens, int $functionIndex, int $functionOp break; } - $assignVarEndIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $prevMeaningFul); + $assignVarEndIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $prevMeaningFul); } $assignVarOperatorIndex = $tokens->getPrevTokenOfKind( @@ -377,7 +377,7 @@ private function clearIfSave(Tokens $tokens, int $index): void */ private function isCloseBracePartOfDefinition(Tokens $tokens, int $index): ?int { - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $index); $candidateIndex = $this->isOpenBraceOfLambda($tokens, $index); if (null !== $candidateIndex) { @@ -401,7 +401,7 @@ private function isOpenBraceOfAnonymousClass(Tokens $tokens, int $index): ?int } while ($tokens[$index]->equalsAny([',', [T_STRING], [T_IMPLEMENTS], [T_EXTENDS], [T_NS_SEPARATOR]])); if ($tokens[$index]->equals(')')) { // skip constructor braces and content within - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $index = $tokens->getPrevMeaningfulToken($index); } @@ -425,12 +425,12 @@ private function isOpenBraceOfLambda(Tokens $tokens, int $index): ?int return null; } - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $index = $tokens->getPrevMeaningfulToken($index); if ($tokens[$index]->isGivenKind(CT::T_USE_LAMBDA)) { $index = $tokens->getPrevTokenOfKind($index, [')']); - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $index = $tokens->getPrevMeaningfulToken($index); } @@ -464,7 +464,7 @@ private function isOpenBraceOfMatch(Tokens $tokens, int $index): ?int return null; } - $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $index = $tokens->getPrevMeaningfulToken($index); return $tokens[$index]->isGivenKind(T_MATCH) ? $index : null; @@ -478,7 +478,7 @@ private function isUsedInCatchOrFinally(Tokens $tokens, int $returnVarIndex, int return false; } $tryOpenIndex = $tokens->getNextTokenOfKind($tryIndex, ['{']); - $tryCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tryOpenIndex); + $tryCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $tryOpenIndex); // Find catch or finally $nextIndex = $tokens->getNextMeaningfulToken($tryCloseIndex); @@ -489,7 +489,7 @@ private function isUsedInCatchOrFinally(Tokens $tokens, int $returnVarIndex, int // Find catches while ($tokens[$nextIndex]->isGivenKind(T_CATCH)) { $catchOpenIndex = $tokens->getNextTokenOfKind($nextIndex, ['{']); - $catchCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $catchOpenIndex); + $catchCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $catchOpenIndex); if ($catchCloseIndex >= $functionCloseIndex) { return false; @@ -515,7 +515,7 @@ private function isUsedInCatchOrFinally(Tokens $tokens, int $returnVarIndex, int return false; } $finallyOpenIndex = $tokens->getNextTokenOfKind($finallyIndex, ['{']); - $finallyCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $finallyOpenIndex); + $finallyCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $finallyOpenIndex); $varIndex = $tokens->getNextTokenOfKind($finallyOpenIndex, [$tokens[$returnVarIndex]]); // Check if the variable is used in the finally block if (null !== $varIndex && $varIndex < $finallyCloseIndex) { diff --git a/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php b/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php index bc222aa318b..d4d9e154d0b 100644 --- a/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php +++ b/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php @@ -121,7 +121,7 @@ private function isStrictOrNullableReturnTypeFunction(Tokens $tokens, int $retur return false; } $openingCurlyBraceIndex = $tokens->getNextTokenOfKind($functionIndex, ['{']); - $closingCurlyBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openingCurlyBraceIndex); + $closingCurlyBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $openingCurlyBraceIndex); } while ($closingCurlyBraceIndex < $returnIndex); $possibleVoidIndex = $tokens->getPrevMeaningfulToken($openingCurlyBraceIndex); diff --git a/src/Fixer/Semicolon/NoEmptyStatementFixer.php b/src/Fixer/Semicolon/NoEmptyStatementFixer.php index 15c1e670df9..d8c25a9c2cd 100644 --- a/src/Fixer/Semicolon/NoEmptyStatementFixer.php +++ b/src/Fixer/Semicolon/NoEmptyStatementFixer.php @@ -69,7 +69,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // skip T_FOR parenthesis to ignore double `;` like `for ($i = 1; ; ++$i) {...}` if ($tokens[$index]->isGivenKind(T_FOR)) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextMeaningfulToken($index)) + 1; + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $tokens->getNextMeaningfulToken($index)) + 1; continue; } @@ -131,7 +131,7 @@ private function fixSemicolonAfterCurlyBraceClose(Tokens $tokens, int $index, in $beforeCurlyOpeningKinds = [T_ELSE, T_FINALLY, T_NAMESPACE, T_OPEN_TAG]; } - $curlyOpeningIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $curlyCloseIndex); + $curlyOpeningIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $curlyCloseIndex); $beforeCurlyOpeningIndex = $tokens->getPrevMeaningfulToken($curlyOpeningIndex); if ($tokens[$beforeCurlyOpeningIndex]->isGivenKind($beforeCurlyOpeningKinds) || $tokens[$beforeCurlyOpeningIndex]->equalsAny([';', '{', '}'])) { @@ -165,7 +165,7 @@ private function fixSemicolonAfterCurlyBraceClose(Tokens $tokens, int $index, in return; } - $openingBraceIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $beforeCurlyOpeningIndex); + $openingBraceIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $beforeCurlyOpeningIndex); $beforeOpeningBraceIndex = $tokens->getPrevMeaningfulToken($openingBraceIndex); if ($tokens[$beforeOpeningBraceIndex]->isGivenKind([T_IF, T_ELSEIF, T_FOR, T_FOREACH, T_WHILE, T_SWITCH, T_CATCH, T_DECLARE])) { diff --git a/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php b/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php index 63be6cfe5cb..8630a865a54 100644 --- a/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php +++ b/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php @@ -80,7 +80,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if (true === $this->configuration['remove_in_empty_for_expressions']) { if ($tokens[$index]->isGivenKind(T_FOR)) { $index = $tokens->getNextMeaningfulToken($index); - $insideForParenthesesUntil = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $insideForParenthesesUntil = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); continue; } diff --git a/src/Fixer/Strict/StrictParamFixer.php b/src/Fixer/Strict/StrictParamFixer.php index d9280969684..8ed54dd1e71 100644 --- a/src/Fixer/Strict/StrictParamFixer.php +++ b/src/Fixer/Strict/StrictParamFixer.php @@ -94,7 +94,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void private function fixFunction(Tokens $tokens, int $functionIndex, array $functionParams): void { $startBraceIndex = $tokens->getNextTokenOfKind($functionIndex, ['(']); - $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startBraceIndex); + $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $startBraceIndex); $paramsQuantity = 0; $expectParam = true; @@ -107,13 +107,13 @@ private function fixFunction(Tokens $tokens, int $functionIndex, array $function } if ($token->equals('(')) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); continue; } if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, $index); continue; } diff --git a/src/Fixer/Whitespace/ArrayIndentationFixer.php b/src/Fixer/Whitespace/ArrayIndentationFixer.php index 76789c87fd4..7d7b30727ad 100644 --- a/src/Fixer/Whitespace/ArrayIndentationFixer.php +++ b/src/Fixer/Whitespace/ArrayIndentationFixer.php @@ -74,7 +74,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void || ($token->equals('(') && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(T_ARRAY)) ) { $endIndex = $tokens->findBlockEnd( - $token->equals('(') ? Tokens::BLOCK_TYPE_PARENTHESIS_BRACE : Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, + $token->equals('(') ? Tokens::BLOCK_TYPE_PARENTHESIS : Tokens::BLOCK_TYPE_ARRAY_BRACKET, $index ); diff --git a/src/Fixer/Whitespace/MethodChainingIndentationFixer.php b/src/Fixer/Whitespace/MethodChainingIndentationFixer.php index 2830246a50c..7a346b39e98 100644 --- a/src/Fixer/Whitespace/MethodChainingIndentationFixer.php +++ b/src/Fixer/Whitespace/MethodChainingIndentationFixer.php @@ -80,7 +80,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $tokens[$index - 1] = new Token([T_WHITESPACE, $lineEnding.$expectedIndent]); } - $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $endParenthesisIndex); + $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $endParenthesisIndex); for ($searchIndex = $index + 1; $searchIndex < $endParenthesisIndex; ++$searchIndex) { $searchToken = $tokens[$searchIndex]; @@ -116,7 +116,7 @@ private function getExpectedIndentAt(Tokens $tokens, int $index): string for ($i = $index; $i >= 0; --$i) { if ($tokens[$i]->equals(')')) { - $i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $i); + $i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $i); } $currentIndent = $this->getIndentAt($tokens, $i); @@ -201,11 +201,11 @@ private function currentLineRequiresExtraIndentLevel(Tokens $tokens, int $start, return $tokens[$thirdMeaningful]->equals('(') - && $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $thirdMeaningful) > $end; + && $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $thirdMeaningful) > $end; } return !$tokens[$end]->equals(')') - || $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $end) >= $start; + || $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $end) >= $start; } } diff --git a/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php b/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php index b3a0849f6f5..c0746e3cdfe 100644 --- a/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php +++ b/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php @@ -57,7 +57,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if (\in_array('inside', $this->configuration['positions'], true)) { if ($token->equals('[')) { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_BRACKET, $index); } else { $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE, $index); } diff --git a/src/Fixer/Whitespace/SpacesInsideParenthesesFixer.php b/src/Fixer/Whitespace/SpacesInsideParenthesesFixer.php index fadf64317da..2c77f898dfd 100644 --- a/src/Fixer/Whitespace/SpacesInsideParenthesesFixer.php +++ b/src/Fixer/Whitespace/SpacesInsideParenthesesFixer.php @@ -94,7 +94,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); // remove space after opening `(` if (!$tokens[$tokens->getNextNonWhitespace($index)]->isComment()) { @@ -114,7 +114,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); // if not other content than spaces in block remove spaces $blockContent = $this->getBlockContent($index, $endParenthesisIndex, $tokens); @@ -135,7 +135,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ($afterParenthesisToken->isGivenKind(CT::T_USE_LAMBDA)) { $useStartParenthesisIndex = $tokens->getNextTokenOfKind($afterParenthesisIndex, ['(']); - $useEndParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $useStartParenthesisIndex); + $useEndParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $useStartParenthesisIndex); // add single-line edge whitespaces inside use parentheses $this->fixParenthesisInnerEdge($tokens, $useStartParenthesisIndex, $useEndParenthesisIndex); diff --git a/src/Fixer/Whitespace/StatementIndentationFixer.php b/src/Fixer/Whitespace/StatementIndentationFixer.php index 40e4971be24..78176e08f43 100644 --- a/src/Fixer/Whitespace/StatementIndentationFixer.php +++ b/src/Fixer/Whitespace/StatementIndentationFixer.php @@ -184,9 +184,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } elseif ($token->isGivenKind(CT::T_GROUP_IMPORT_BRACE_OPEN)) { $endIndex = $tokens->getNextTokenOfKind($index, [[CT::T_GROUP_IMPORT_BRACE_CLOSE]]); } elseif ($token->equals('{')) { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); } elseif ($token->equals('(')) { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); } else { $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ATTRIBUTE, $index); } @@ -230,7 +230,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ($token->isGivenKind($blockSignatureFirstTokens)) { for ($endIndex = $index + 1, $max = \count($tokens); $endIndex < $max; ++$endIndex) { if ($tokens[$endIndex]->equals('(')) { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $endIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $endIndex); continue; } @@ -284,7 +284,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void for ($max = \count($tokens); $endIndex < $max; ++$endIndex) { if ($tokens[$endIndex]->equals('(')) { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $endIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $endIndex); continue; } @@ -466,11 +466,11 @@ private function findStatementEndIndex(Tokens $tokens, int $index, int $parentSc if ($searchEndToken->equalsAny(['(', '{', [CT::T_ARRAY_SQUARE_BRACE_OPEN]])) { if ($searchEndToken->equals('(')) { - $blockType = Tokens::BLOCK_TYPE_PARENTHESIS_BRACE; + $blockType = Tokens::BLOCK_TYPE_PARENTHESIS; } elseif ($searchEndToken->equals('{')) { - $blockType = Tokens::BLOCK_TYPE_CURLY_BRACE; + $blockType = Tokens::BLOCK_TYPE_BRACE; } else { - $blockType = Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE; + $blockType = Tokens::BLOCK_TYPE_ARRAY_BRACKET; } $searchEndIndex = $tokens->findBlockEnd($blockType, $searchEndIndex); @@ -497,7 +497,7 @@ private function findCaseBlockEnd(Tokens $tokens, int $index): array if ($tokens[$index]->isGivenKind(T_SWITCH)) { $braceIndex = $tokens->getNextMeaningfulToken( $tokens->findBlockEnd( - Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + Tokens::BLOCK_TYPE_PARENTHESIS, $tokens->getNextMeaningfulToken($index) ) ); @@ -505,14 +505,14 @@ private function findCaseBlockEnd(Tokens $tokens, int $index): array if ($tokens[$braceIndex]->equals(':')) { $index = $this->alternativeSyntaxAnalyzer->findAlternativeSyntaxBlockEnd($tokens, $index); } else { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $braceIndex); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $braceIndex); } continue; } if ($tokens[$index]->equals('{')) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); continue; } diff --git a/src/Indicator/PhpUnitTestCaseIndicator.php b/src/Indicator/PhpUnitTestCaseIndicator.php index b4942d93d20..fe83c992c7e 100644 --- a/src/Indicator/PhpUnitTestCaseIndicator.php +++ b/src/Indicator/PhpUnitTestCaseIndicator.php @@ -82,7 +82,7 @@ public function findPhpUnitClasses(Tokens $tokens): iterable return; } - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startIndex); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $startIndex); yield [$startIndex, $endIndex]; } diff --git a/src/Tokenizer/Analyzer/AlternativeSyntaxAnalyzer.php b/src/Tokenizer/Analyzer/AlternativeSyntaxAnalyzer.php index 723d4c9505f..ca15134e68c 100644 --- a/src/Tokenizer/Analyzer/AlternativeSyntaxAnalyzer.php +++ b/src/Tokenizer/Analyzer/AlternativeSyntaxAnalyzer.php @@ -49,7 +49,7 @@ public function belongsToAlternativeSyntax(Tokens $tokens, int $index): bool return false; } - $openParenthesisIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $prevIndex); + $openParenthesisIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $prevIndex); $beforeOpenParenthesisIndex = $tokens->getPrevMeaningfulToken($openParenthesisIndex); return $tokens[$beforeOpenParenthesisIndex]->isGivenKind([ @@ -107,7 +107,7 @@ private function isStartOfAlternativeSyntaxBlock(Tokens $tokens, int $index): bo if ($tokens[$index]->equals('(')) { $index = $tokens->getNextMeaningfulToken( - $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index) + $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index) ); } diff --git a/src/Tokenizer/Analyzer/CommentsAnalyzer.php b/src/Tokenizer/Analyzer/CommentsAnalyzer.php index d0d87ef2c3c..ec2f66ca142 100644 --- a/src/Tokenizer/Analyzer/CommentsAnalyzer.php +++ b/src/Tokenizer/Analyzer/CommentsAnalyzer.php @@ -48,7 +48,7 @@ public function isHeaderComment(Tokens $tokens, int $index): bool return false; } - $braceOpenIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $braceCloseIndex); + $braceOpenIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $braceCloseIndex); $declareIndex = $tokens->getPrevMeaningfulToken($braceOpenIndex); if (!$tokens[$declareIndex]->isGivenKind(T_DECLARE)) { return false; @@ -228,7 +228,7 @@ private function isValidControl(Tokens $tokens, Token $docsToken, int $controlIn } $openParenthesisIndex = $tokens->getNextMeaningfulToken($controlIndex); - $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesisIndex); + $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openParenthesisIndex); $docsContent = $docsToken->getContent(); for ($index = $openParenthesisIndex + 1; $index < $closeParenthesisIndex; ++$index) { diff --git a/src/Tokenizer/Analyzer/ControlCaseStructuresAnalyzer.php b/src/Tokenizer/Analyzer/ControlCaseStructuresAnalyzer.php index cb7cf9c43bd..fcf1e7cf61d 100644 --- a/src/Tokenizer/Analyzer/ControlCaseStructuresAnalyzer.php +++ b/src/Tokenizer/Analyzer/ControlCaseStructuresAnalyzer.php @@ -79,13 +79,13 @@ public static function findControlStructures(Tokens $tokens, array $types): \Gen if ($token->isGivenKind(T_SWITCH)) { $index = $tokens->getNextMeaningfulToken($index); - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $stack[$depth]['open'] = $tokens->getNextMeaningfulToken($index); $stack[$depth]['alternative_syntax'] = $tokens[$stack[$depth]['open']]->equals(':'); } elseif (\defined('T_MATCH') && $token->isGivenKind(T_MATCH)) { // @TODO: drop condition when PHP 8.0+ is required $index = $tokens->getNextMeaningfulToken($index); - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $stack[$depth]['open'] = $tokens->getNextMeaningfulToken($index); } elseif (\defined('T_ENUM') && $token->isGivenKind(T_ENUM)) { diff --git a/src/Tokenizer/Analyzer/FunctionsAnalyzer.php b/src/Tokenizer/Analyzer/FunctionsAnalyzer.php index 51b2ac03e6f..f2f61d953ce 100644 --- a/src/Tokenizer/Analyzer/FunctionsAnalyzer.php +++ b/src/Tokenizer/Analyzer/FunctionsAnalyzer.php @@ -142,7 +142,7 @@ public function isGlobalFunctionCall(Tokens $tokens, int $index): bool public function getFunctionArguments(Tokens $tokens, int $functionIndex): array { $argumentsStart = $tokens->getNextTokenOfKind($functionIndex, ['(']); - $argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $argumentsStart); + $argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $argumentsStart); $argumentAnalyzer = new ArgumentsAnalyzer(); $arguments = []; @@ -157,7 +157,7 @@ public function getFunctionArguments(Tokens $tokens, int $functionIndex): array public function getFunctionReturnType(Tokens $tokens, int $methodIndex): ?TypeAnalysis { $argumentsStart = $tokens->getNextTokenOfKind($methodIndex, ['(']); - $argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $argumentsStart); + $argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $argumentsStart); $typeColonIndex = $tokens->getNextMeaningfulToken($argumentsEnd); if (!$tokens[$typeColonIndex]->isGivenKind(CT::T_TYPE_COLON)) { @@ -225,11 +225,11 @@ private function buildFunctionsAnalysis(Tokens $tokens): void $i = $tokens->getNextTokenOfKind($i, ['(', '{']); if ($tokens[$i]->equals('(')) { // anonymous class - $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $i); + $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $i); $i = $tokens->getNextTokenOfKind($i, ['{']); } - $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $i); + $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $i); continue; } diff --git a/src/Tokenizer/Analyzer/NamespacesAnalyzer.php b/src/Tokenizer/Analyzer/NamespacesAnalyzer.php index 3890523ae13..a2954e44286 100644 --- a/src/Tokenizer/Analyzer/NamespacesAnalyzer.php +++ b/src/Tokenizer/Analyzer/NamespacesAnalyzer.php @@ -42,7 +42,7 @@ public function getDeclarations(Tokens $tokens): array $shortName = end($declarationParts); if ($tokens[$declarationEndIndex]->equals('{')) { - $scopeEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $declarationEndIndex); + $scopeEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $declarationEndIndex); } else { $scopeEndIndex = $tokens->getNextTokenOfKind($declarationEndIndex, [[T_NAMESPACE]]); if (null === $scopeEndIndex) { diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index dcd7f137fed..8be2a2329aa 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -627,7 +627,7 @@ public function isWhilePartOfDoWhile(int $index): bool return false; } - $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $endIndex); + $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $endIndex); $beforeStartIndex = $tokens->getPrevMeaningfulToken($startIndex); return $tokens[$beforeStartIndex]->isGivenKind(T_DO); diff --git a/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php b/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php index 1a690b89aa5..6ccef0bb7a7 100644 --- a/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php +++ b/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php @@ -67,7 +67,7 @@ public function process(Tokens $tokens, Token $token, int $index): void return; } - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $tokens[$index] = new Token([CT::T_BRACE_CLASS_INSTANTIATION_OPEN, '(']); $tokens[$closeIndex] = new Token([CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, ')']); diff --git a/src/Tokenizer/Transformer/ConstructorPromotionTransformer.php b/src/Tokenizer/Transformer/ConstructorPromotionTransformer.php index cdb282d35bb..38c5beff4a7 100644 --- a/src/Tokenizer/Transformer/ConstructorPromotionTransformer.php +++ b/src/Tokenizer/Transformer/ConstructorPromotionTransformer.php @@ -47,7 +47,7 @@ public function process(Tokens $tokens, Token $token, int $index): void /** @var int $openParenthesisIndex */ $openParenthesisIndex = $tokens->getNextMeaningfulToken($functionNameIndex); // we are @ '(' now - $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesisIndex); + $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $openParenthesisIndex); for ($argsIndex = $openParenthesisIndex; $argsIndex < $closeParenthesisIndex; ++$argsIndex) { if ($tokens[$argsIndex]->isGivenKind(T_PUBLIC)) { diff --git a/src/Tokenizer/Transformer/CurlyBraceTransformer.php b/src/Tokenizer/Transformer/CurlyBraceTransformer.php index ff222660969..10d120990fa 100644 --- a/src/Tokenizer/Transformer/CurlyBraceTransformer.php +++ b/src/Tokenizer/Transformer/CurlyBraceTransformer.php @@ -173,7 +173,7 @@ private function transformIntoCurlyIndexBraces(Tokens $tokens, Token $token, int if ( $tokens[$prevIndex]->equals(')') && !$tokens[$tokens->getPrevMeaningfulToken( - $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $prevIndex) + $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $prevIndex) )]->isGivenKind(T_ARRAY) ) { return; @@ -220,14 +220,14 @@ private function transformIntoDynamicClassConstantFetchBraces(Tokens $tokens, To return; } - $prevMeaningfulTokenIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $prevMeaningfulTokenIndex); + $prevMeaningfulTokenIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $prevMeaningfulTokenIndex); $prevMeaningfulTokenIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulTokenIndex); if (!$tokens[$prevMeaningfulTokenIndex]->equals('}')) { return; } - $prevMeaningfulTokenIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $prevMeaningfulTokenIndex); + $prevMeaningfulTokenIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_BRACE, $prevMeaningfulTokenIndex); $prevMeaningfulTokenIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulTokenIndex); } @@ -243,7 +243,7 @@ private function transformIntoDynamicClassConstantFetchBraces(Tokens $tokens, To } /** - * We do not want to rely on `$tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index)` here, + * We do not want to rely on `$tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index)` here, * as it relies on block types that are assuming that `}` tokens are already transformed to Custom Tokens that are allowing to distinguish different block types. * As we are just about to transform `{` and `}` into Custom Tokens by this transformer, thus we need to compare those tokens manually by content without using `Tokens::findBlockEnd`. */ diff --git a/src/Tokenizer/Transformer/DisjunctiveNormalFormTypeParenthesisTransformer.php b/src/Tokenizer/Transformer/DisjunctiveNormalFormTypeParenthesisTransformer.php index 21d062b0067..762cd98d3c0 100644 --- a/src/Tokenizer/Transformer/DisjunctiveNormalFormTypeParenthesisTransformer.php +++ b/src/Tokenizer/Transformer/DisjunctiveNormalFormTypeParenthesisTransformer.php @@ -43,9 +43,9 @@ public function process(Tokens $tokens, Token $token, int $index): void { if ($token->equals('(') && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(CT::T_TYPE_ALTERNATION)) { $openIndex = $index; - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, $index); } elseif ($token->equals(')') && $tokens[$tokens->getNextMeaningfulToken($index)]->isGivenKind(CT::T_TYPE_ALTERNATION)) { - $openIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index); + $openIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $index); $closeIndex = $index; } else { return; diff --git a/src/Tokenizer/Transformer/SquareBraceTransformer.php b/src/Tokenizer/Transformer/SquareBraceTransformer.php index 46e5b12deb2..60217e16794 100644 --- a/src/Tokenizer/Transformer/SquareBraceTransformer.php +++ b/src/Tokenizer/Transformer/SquareBraceTransformer.php @@ -71,7 +71,7 @@ public function getCustomTokens(): array private function transformIntoArraySquareBrace(Tokens $tokens, int $index): void { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_BRACKET, $index); $tokens[$index] = new Token([CT::T_ARRAY_SQUARE_BRACE_OPEN, '[']); $tokens[$endIndex] = new Token([CT::T_ARRAY_SQUARE_BRACE_CLOSE, ']']); @@ -79,7 +79,7 @@ private function transformIntoArraySquareBrace(Tokens $tokens, int $index): void private function transformIntoDestructuringSquareBrace(Tokens $tokens, int $index): void { - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_BRACKET, $index); $tokens[$index] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, '[']); $tokens[$endIndex] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE, ']']); @@ -89,7 +89,7 @@ private function transformIntoDestructuringSquareBrace(Tokens $tokens, int $inde while ($index < $endIndex) { if ($tokens[$index]->equals('[') && $tokens[$previousMeaningfulIndex]->equalsAny([[CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN], ','])) { - $tokens[$tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index)] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE, ']']); + $tokens[$tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_BRACKET, $index)] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE, ']']); $tokens[$index] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, '[']); } diff --git a/src/Tokenizer/Transformer/TypeColonTransformer.php b/src/Tokenizer/Transformer/TypeColonTransformer.php index 7fed9de27e3..f752786221a 100644 --- a/src/Tokenizer/Transformer/TypeColonTransformer.php +++ b/src/Tokenizer/Transformer/TypeColonTransformer.php @@ -61,7 +61,7 @@ public function process(Tokens $tokens, Token $token, int $index): void return; } - $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $endIndex); + $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, $endIndex); $prevIndex = $tokens->getPrevMeaningfulToken($startIndex); $prevToken = $tokens[$prevIndex]; diff --git a/src/Tokenizer/Transformer/UseTransformer.php b/src/Tokenizer/Transformer/UseTransformer.php index 5aa0c027be5..083eefc3086 100644 --- a/src/Tokenizer/Transformer/UseTransformer.php +++ b/src/Tokenizer/Transformer/UseTransformer.php @@ -67,7 +67,7 @@ public function process(Tokens $tokens, Token $token, int $index): void } $index = $tokens->getNextTokenOfKind($index, ['{']); - $innerLimit = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $innerLimit = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $index); while ($index < $innerLimit) { $token = $tokens[++$index]; diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index 478c270df88..85e712b4c49 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -478,7 +478,7 @@ public function testAllCodeContainSingleClassy(string $className): void throw new \UnexpectedValueException('Classy without {} - braces.'); } - $classyEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nextTokenOfKind); + $classyEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_BRACE, $nextTokenOfKind); self::assertNull($tokens->getNextNonWhitespace($classyEndIndex), sprintf('File "%s" should only contains a single classy.', $file)); } diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index 558096e9b1d..4f29161928e 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -724,29 +724,29 @@ public static function provideFindBlockEndCases(): iterable { yield [4, '{$bar};', Tokens::BLOCK_TYPE_DYNAMIC_PROP_BRACE, 3]; - yield [4, '', Tokens::BLOCK_TYPE_CURLY_BRACE, 5]; + yield [6, '', Tokens::BLOCK_TYPE_BRACE, 5]; - yield [11, '{"set_{$name}"}(42);', Tokens::BLOCK_TYPE_DYNAMIC_PROP_BRACE, 3]; - yield [19, 'findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, 2)); + self::assertSame(7, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, 2)); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessageMatches('/^Invalid param \$startIndex - not a proper block "start"\.$/'); - $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, 7); + $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS, 7); } public function testFindBlockStartEdgeCalledMultipleTimes(): void @@ -883,12 +883,12 @@ public function testFindBlockStartEdgeCalledMultipleTimes(): void Tokens::clearCache(); $tokens = Tokens::fromCode('findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, 7)); + self::assertSame(2, $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, 7)); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessageMatches('/^Invalid param \$startIndex - not a proper block "end"\.$/'); - $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, 2); + $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS, 2); } public function testEmptyTokens(): void @@ -1323,7 +1323,7 @@ public static function provideDetectBlockTypeCases(): iterable { yield [ [ - 'type' => Tokens::BLOCK_TYPE_CURLY_BRACE, + 'type' => Tokens::BLOCK_TYPE_BRACE, 'isStart' => true, ], 'getBlockEdgeCachingTestTokens(); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, 5); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, 5); self::assertSame(9, $endIndex); $tokens->offsetSet(5, new Token('(')); @@ -1723,22 +1723,22 @@ public function testBlockEdgeCachingOffsetSet(): void $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid param $startIndex - not a proper block "start".'); - $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, 5); + $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, 5); } public function testBlockEdgeCachingClearAt(): void { $tokens = $this->getBlockEdgeCachingTestTokens(); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, 5); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, 5); self::assertSame(9, $endIndex); $tokens->clearAt(7); // note: offsetUnset doesn't work here - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, 5); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, 5); self::assertSame(9, $endIndex); $tokens->clearEmptyTokens(); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, 5); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, 5); self::assertSame(8, $endIndex); } @@ -1746,12 +1746,12 @@ public function testBlockEdgeCachingInsertSlices(): void { $tokens = $this->getBlockEdgeCachingTestTokens(); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, 5); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, 5); self::assertSame(9, $endIndex); $tokens->insertSlices([6 => [new Token([T_COMMENT, '/* A */'])], new Token([T_COMMENT, '/* B */'])]); - $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, 5); + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_BRACKET, 5); self::assertSame(11, $endIndex); }