Skip to content

Commit

Permalink
NoExtraBlankLinesFixer - PHP8 throw support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum committed Dec 31, 2020
1 parent bb6ee85 commit f6c6bff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/Fixer/Whitespace/NoExtraBlankLinesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function configure(array $configuration = null)
T_DEFAULT => 'fixAfterToken',
T_RETURN => 'fixAfterToken',
T_SWITCH => 'fixAfterToken',
T_THROW => 'fixAfterToken',
T_THROW => 'fixAfterThrowToken',
T_USE => 'removeBetweenUse',
T_WHITESPACE => 'removeMultipleBlankLines',
CT::T_USE_TRAIT => 'removeBetweenUse',
Expand Down Expand Up @@ -408,6 +408,13 @@ private function fixAfterToken($index)
$this->removeEmptyLinesAfterLineWithTokenAt($index);
}

private function fixAfterThrowToken($index)
{
if ($this->tokens[$this->tokens->getPrevMeaningfulToken($index)]->equalsAny([';', '{', '}', ':', [T_OPEN_TAG]])) {
$this->fixAfterToken($index);
}
}

/**
* Remove white line(s) after the index of a block type,
* but only if the block is not on one line.
Expand Down
10 changes: 7 additions & 3 deletions tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1252,15 +1252,19 @@ public function provideFix80Cases()
yield [
'<?php
$a = $bar ?? throw new \Exception();
$a = $bar ?? throw new \Exception();
$a = $bar ?? throw new \Exception();
',
'<?php
$a = $bar ?? throw new \Exception();
];

yield [
'<?php
$a = $bar ?? throw new \Exception();
$a = $bar ?? throw new \Exception();
// Now, we gonna use it!
var_dump($a);
',
];
}
Expand Down

0 comments on commit f6c6bff

Please sign in to comment.