Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SingleSpaceAfterConstructFixer - allow multiline const #6167

Merged
merged 1 commit into from Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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