Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoExtraBlankLinesFixer - remove blank lines after open tag #3888

Merged
merged 1 commit into from Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;