Skip to content

Commit 5881633

Browse files
kubawerloskeradus
authored andcommitted
SingleLineAfterImportsFixer - fix for line after import already added using CRLF
1 parent c0d6a34 commit 5881633

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Fixer/Import/SingleLineAfterImportsFixer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
137137

138138
if ($tokens[$insertIndex]->isWhitespace()) {
139139
$nextToken = $tokens[$insertIndex];
140+
if (2 === substr_count($nextToken->getContent(), "\n")) {
141+
continue;
142+
}
140143
$nextMeaningfulAfterUseIndex = $tokens->getNextMeaningfulToken($insertIndex);
141144
if (null !== $nextMeaningfulAfterUseIndex && $tokens[$nextMeaningfulAfterUseIndex]->isGivenKind(T_USE)) {
142145
if (substr_count($nextToken->getContent(), "\n") < 2) {

tests/Fixer/Import/SingleLineAfterImportsFixerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,13 @@ class Test {}
436436
use some\a\ClassA; use function some\a\fn_a; use const some\c;
437437
',
438438
],
439+
[
440+
str_replace("\n", "\r\n", '<?php
441+
use Foo;
442+
443+
class Bar {}
444+
'),
445+
],
439446
];
440447
}
441448

0 commit comments

Comments
 (0)