Skip to content

Commit

Permalink
bug PHP-CS-Fixer#5029 SingleLineAfterImportsFixer - fix for line afte…
Browse files Browse the repository at this point in the history
…r import already added using CRLF (kubawerlos)

This PR was squashed before being merged into the 2.15 branch.

Discussion
----------

SingleLineAfterImportsFixer - fix for line after import already added using CRLF

Fixes PHP-CS-Fixer#5028

Commits
-------

5881633 SingleLineAfterImportsFixer - fix for line after import already added using CRLF
  • Loading branch information
keradus committed Jun 27, 2020
2 parents 2d49b15 + 5881633 commit dfc4f07
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Fixer/Import/SingleLineAfterImportsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)

if ($tokens[$insertIndex]->isWhitespace()) {
$nextToken = $tokens[$insertIndex];
if (2 === substr_count($nextToken->getContent(), "\n")) {
continue;
}
$nextMeaningfulAfterUseIndex = $tokens->getNextMeaningfulToken($insertIndex);
if (null !== $nextMeaningfulAfterUseIndex && $tokens[$nextMeaningfulAfterUseIndex]->isGivenKind(T_USE)) {
if (substr_count($nextToken->getContent(), "\n") < 2) {
Expand Down
7 changes: 7 additions & 0 deletions tests/Fixer/Import/SingleLineAfterImportsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ class Test {}
use some\a\ClassA; use function some\a\fn_a; use const some\c;
',
],
[
str_replace("\n", "\r\n", '<?php
use Foo;
class Bar {}
'),
],
];
}

Expand Down

0 comments on commit dfc4f07

Please sign in to comment.