Skip to content

Commit

Permalink
SingleSpaceAfterConstructFixer - allow multiline const
Browse files Browse the repository at this point in the history
  • Loading branch information
YAhiru authored and SpacePossum committed Dec 15, 2021
1 parent 56d8399 commit 75c640f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Up @@ -583,6 +583,50 @@ public function provideFixWithConstCases(): array
'<?php class Foo { const /* foo */FOO = 9000; }',
'<?php class Foo { const /* foo */FOO = 9000; }',
],
['<?php class Foo {
const
FOO = 9000,
BAR = 10000;
}',
],
[
'<?php
const
A = 3,
B = 3
?>',
],
[
'<?php
const A = 3 ?>
<?php
[ ,
,
,$z
] = foo() ;',
'<?php
const A = 3 ?>
<?php
[ ,
,
,$z
] = foo() ;',
],
[
'<?php
const A
=
1;
',
'<?php
const
A
=
1;
',
],
];
}

Expand Down

0 comments on commit 75c640f

Please sign in to comment.