Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum committed Dec 14, 2021
1 parent 1b204be commit 924086a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php
Expand Up @@ -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 (
Expand Down Expand Up @@ -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);
}
Expand Down
Expand Up @@ -583,8 +583,7 @@ public function provideFixWithConstCases(): array
'<?php class Foo { const /* foo */FOO = 9000; }',
'<?php class Foo { const /* foo */FOO = 9000; }',
],
[
'<?php class Foo {
['<?php class Foo {
const
FOO = 9000,
BAR = 10000;
Expand All @@ -595,8 +594,39 @@ public function provideFixWithConstCases(): array
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 924086a

Please sign in to comment.