Skip to content

Commit 4e0fc98

Browse files
authored
fix: white space before semi-colon on interface functions (#141)
* test: try to reproduce regression * fix: white space before semi-colon on interface functions
1 parent a06b1ae commit 4e0fc98

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ private function splitArgs(Tokens $tokens, $index): void
168168
$end = $tokens->getNextTokenOfKind($closeBraceIndex, [';', '{']);
169169

170170
$tokens->removeLeadingWhitespace($end);
171-
$tokens->ensureWhitespaceAtIndex($end, 0, ' ');
171+
172+
if (';' !== $tokens[$end]->getContent()) {
173+
$tokens->ensureWhitespaceAtIndex($end, 0, ' ');
174+
}
172175
}
173176

174177
$linebreaks = [$openBraceIndex, $closeBraceIndex - 1];
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace tests\UseCase\LineBreakBetweenMethods\Regression;
6+
7+
use PedroTroller\CS\Fixer\CodingStyle\LineBreakBetweenMethodArgumentsFixer;
8+
use tests\UseCase;
9+
10+
/**
11+
* https://github.com/PedroTroller/PhpCSFixer-Custom-Fixers/issues/139.
12+
*/
13+
final class Case6 implements UseCase
14+
{
15+
public function getFixers(): iterable
16+
{
17+
$fixer = new LineBreakBetweenMethodArgumentsFixer();
18+
19+
$fixer->configure([
20+
'max-args' => false,
21+
'max-length' => 1,
22+
'automatic-argument-merge' => false,
23+
]);
24+
25+
yield $fixer;
26+
}
27+
28+
public function getRawScript(): string
29+
{
30+
return <<<'PHP'
31+
<?php
32+
33+
interface Foo {
34+
public function bar(
35+
string $path
36+
): string;
37+
}
38+
PHP;
39+
}
40+
41+
public function getExpectation(): string
42+
{
43+
return <<<'PHP'
44+
<?php
45+
46+
interface Foo {
47+
public function bar(
48+
string $path
49+
): string;
50+
}
51+
PHP;
52+
}
53+
54+
public function getMinSupportedPhpVersion(): int
55+
{
56+
return 0;
57+
}
58+
}

0 commit comments

Comments
 (0)