Skip to content

Commit

Permalink
feature: BlankLineBetweenImportGroupsFixer - keep indent (#7122)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Jul 5, 2023
1 parent 734f765 commit 6db6a98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
9 changes: 3 additions & 6 deletions src/Fixer/Whitespace/BlankLineBetweenImportGroupsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use PhpCsFixer\FixerDefinition\CodeSample;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Analyzer\WhitespacesAnalyzer;
use PhpCsFixer\Tokenizer\CT;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Tokenizer\TokensAnalyzer;

Expand Down Expand Up @@ -154,12 +154,9 @@ private function ensureLine(Tokens $tokens, int $index): void
}

$index = $this->getInsertIndex($tokens, $index);
$indent = WhitespacesAnalyzer::detectIndent($tokens, $index);

if ($tokens[$index]->isWhitespace()) {
$tokens[$index] = new Token([T_WHITESPACE, $lineEnding]);
} else {
$tokens->insertSlices([$index + 1 => [new Token([T_WHITESPACE, $lineEnding])]]);
}
$tokens->ensureWhitespaceAtIndex($index, 1, $lineEnding.$indent);
}

private function getInsertIndex(Tokens $tokens, int $index): int
Expand Down
28 changes: 14 additions & 14 deletions tests/Fixer/Whitespace/BlankLineBetweenImportGroupsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,23 +428,23 @@ public static function provideFixTypesOrderAndNewlinesCases(): iterable
namespace A\B6 {
use C1\B1;
use const C6\Z1;
use const C6\Z1;
use C2\B2;
use C2\B2;
use const C7\Z2;
use const C7\Z2;
use C3\B3;
use C3\B3;
use const C8\Z3;
use const C8\Z3;
use C4\B4;
use C4\B4;
use const C9\Z4;
use const C9\Z4;
use C5\B5;
use C5\B5;
use const C0\Z5;
use const C0\Z5;
}
',
'<?php
Expand All @@ -463,27 +463,27 @@ public static function provideFixTypesOrderAndNewlinesCases(): iterable
namespace A\B1 {
use C\B;
use const C\Z;
use const C\Z;
}
namespace A\B2 {
use C\B;
use const C\Z;
use const C\Z;
}
namespace A\B3 {
use C\B;
use const C\Z;
use const C\Z;
}
namespace A\B4 {
use C\B;
use const C\Z;
use const C\Z;
}
namespace A\B5 {
use C\B;
use const C\Z;
use const C\Z;
}
',
'<?php
Expand Down

0 comments on commit 6db6a98

Please sign in to comment.