Skip to content

Commit

Permalink
[CodingStyle] Remove Else as next stmt on NewlineAfterStatementRector (
Browse files Browse the repository at this point in the history
…#3966)

Since we use StmtsAwareInterface, Else, ElseIf, Catch, Finally never be next stmt.
  • Loading branch information
samsonasik committed May 25, 2023
1 parent eb46352 commit d279f71
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
use PhpParser\Comment;
use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Catch_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Do_;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\ElseIf_;
use PhpParser\Node\Stmt\Finally_;
use PhpParser\Node\Stmt\For_;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\Function_;
Expand Down Expand Up @@ -133,7 +130,7 @@ private function processAddNewLine(
$stmt = $node->stmts[$key];
$nextStmt = $node->stmts[$key + 1];

if ($this->shouldSkip($nextStmt, $stmt)) {
if ($this->shouldSkip($stmt)) {
continue;
}

Expand Down Expand Up @@ -219,12 +216,8 @@ private function isRemoved(Stmt $nextStmt, Stmt $stmt): bool
return $parentnextStmt !== $parentCurrentNode;
}

private function shouldSkip(Stmt $nextStmt, Stmt $stmt): bool
private function shouldSkip(Stmt $stmt): bool
{
if (! in_array($stmt::class, self::STMTS_TO_HAVE_NEXT_NEWLINE, true)) {
return true;
}

return in_array($nextStmt::class, [Else_::class, ElseIf_::class, Catch_::class, Finally_::class], true);
return ! in_array($stmt::class, self::STMTS_TO_HAVE_NEXT_NEWLINE, true);
}
}

0 comments on commit d279f71

Please sign in to comment.