Skip to content

Commit

Permalink
bug #3888 NoExtraBlankLinesFixer - remove blank lines after open tag …
Browse files Browse the repository at this point in the history
…(kubawerlos)

This PR was squashed before being merged into the 2.12 branch (closes #3888).

Discussion
----------

NoExtraBlankLinesFixer - remove blank lines after open tag

Commits
-------

377d8cc NoExtraBlankLinesFixer - remove blank lines after open tag
  • Loading branch information
SpacePossum committed Jul 10, 2018
2 parents b63be58 + 377d8cc commit 57857e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Fixer/Whitespace/NoExtraBlankLinesFixer.php
Expand Up @@ -377,11 +377,13 @@ private function removeBetweenUse($index)

private function removeMultipleBlankLines($index)
{
$expected = $this->tokens[$index - 1]->isGivenKind(T_OPEN_TAG) && 1 === Preg::match('/\R$/', $this->tokens[$index - 1]->getContent()) ? 1 : 2;

$parts = Preg::split('/(.*\R)/', $this->tokens[$index]->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$count = \count($parts);

if ($count > 2) {
$this->tokens[$index] = new Token([T_WHITESPACE, $parts[0].$parts[1].rtrim($parts[$count - 1], "\r\n")]);
if ($count > $expected) {
$this->tokens[$index] = new Token([T_WHITESPACE, implode(array_slice($parts, 0, $expected)).rtrim($parts[$count - 1], "\r\n")]);
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php
Expand Up @@ -1103,6 +1103,19 @@ public function provideSwitchCases()
];
}

public function testRemovingEmptyLinesAfterOpenTag()
{
$this->doTest(
'<?php
class Foo {}',
'<?php
class Foo {}'
);
}

/**
* @param string $expected
* @param string $input
Expand Down
Expand Up @@ -5,13 +5,11 @@ Integration of fixers: no_unused_imports,no_extra_blank_lines.
--EXPECT--
<?php


$bar = null;

--INPUT--
<?php


use Foo\Bar;

$bar = null;

0 comments on commit 57857e6

Please sign in to comment.