Skip to content

Commit

Permalink
fix: white space before semi-colon on interface functions (#141)
Browse files Browse the repository at this point in the history
* test: try to reproduce regression

* fix: white space before semi-colon on interface functions
  • Loading branch information
PedroTroller authored May 27, 2021
1 parent a06b1ae commit 4e0fc98
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ private function splitArgs(Tokens $tokens, $index): void
$end = $tokens->getNextTokenOfKind($closeBraceIndex, [';', '{']);

$tokens->removeLeadingWhitespace($end);
$tokens->ensureWhitespaceAtIndex($end, 0, ' ');

if (';' !== $tokens[$end]->getContent()) {
$tokens->ensureWhitespaceAtIndex($end, 0, ' ');
}
}

$linebreaks = [$openBraceIndex, $closeBraceIndex - 1];
Expand Down
58 changes: 58 additions & 0 deletions tests/UseCase/LineBreakBetweenMethods/Regression/Case6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace tests\UseCase\LineBreakBetweenMethods\Regression;

use PedroTroller\CS\Fixer\CodingStyle\LineBreakBetweenMethodArgumentsFixer;
use tests\UseCase;

/**
* https://github.com/PedroTroller/PhpCSFixer-Custom-Fixers/issues/139.
*/
final class Case6 implements UseCase
{
public function getFixers(): iterable
{
$fixer = new LineBreakBetweenMethodArgumentsFixer();

$fixer->configure([
'max-args' => false,
'max-length' => 1,
'automatic-argument-merge' => false,
]);

yield $fixer;
}

public function getRawScript(): string
{
return <<<'PHP'
<?php
interface Foo {
public function bar(
string $path
): string;
}
PHP;
}

public function getExpectation(): string
{
return <<<'PHP'
<?php
interface Foo {
public function bar(
string $path
): string;
}
PHP;
}

public function getMinSupportedPhpVersion(): int
{
return 0;
}
}

0 comments on commit 4e0fc98

Please sign in to comment.