diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index 1c6a16a9e8c..92b25baea43 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -250,16 +250,16 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } + if ($token->isGivenKind(T_CONST) && $this->isMultilineConstant($tokens, $index)) { + continue; + } + if ($token->isComment() || $token->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { if ($tokens[$whitespaceTokenIndex]->equals([T_WHITESPACE]) && str_contains($tokens[$whitespaceTokenIndex]->getContent(), "\n")) { continue; } } - if ($token->isGivenKind(T_CONST) && $this->isMultilineConstant($tokens, $index)) { - continue; - } - $tokens->ensureWhitespaceAtIndex($whitespaceTokenIndex, 0, ' '); if ( @@ -346,9 +346,8 @@ private function isMultilineExtendsOrImplementsWithMoreThanOneAncestor(Tokens $t private function isMultilineConstant(Tokens $tokens, int $index): bool { - $scopeEnd = $tokens->getNextTokenOfKind($index, [';', [T_CLOSE_TAG]]); - - $hasMoreThanOneConstant = null !== $tokens->findSequence([','], $index, $scopeEnd); + $scopeEnd = $tokens->getNextTokenOfKind($index, [';', [T_CLOSE_TAG]]) - 1; + $hasMoreThanOneConstant = null !== $tokens->findSequence([new Token(',')], $index + 1, $scopeEnd); return $hasMoreThanOneConstant && $tokens->isPartialCodeMultiline($index, $scopeEnd); } diff --git a/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php b/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php index abcfa92c4b3..eb1402ef29d 100644 --- a/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php +++ b/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php @@ -583,8 +583,7 @@ public function provideFixWithConstCases(): array '' - ] +?>', + ], + [ + ' + + + +