From 75c640fa9eb4140e81f57e56963720e791cc9d18 Mon Sep 17 00:00:00 2001 From: y_ahiru Date: Sun, 12 Dec 2021 12:44:31 +0000 Subject: [PATCH] SingleSpaceAfterConstructFixer - allow multiline const --- .../SingleSpaceAfterConstructFixer.php | 12 +++++ .../SingleSpaceAfterConstructFixerTest.php | 44 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index 89f32afeb71..92b25baea43 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -250,6 +250,10 @@ 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; @@ -339,4 +343,12 @@ private function isMultilineExtendsOrImplementsWithMoreThanOneAncestor(Tokens $t return false; } + + private function isMultilineConstant(Tokens $tokens, int $index): bool + { + $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 20b6df2fc92..eb1402ef29d 100644 --- a/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php +++ b/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php @@ -583,6 +583,50 @@ public function provideFixWithConstCases(): array '', + ], + [ + ' + + + +