Skip to content

Commit

Permalink
[CodingStyle] Skip inside return statement on NewlineAfterStatementRe…
Browse files Browse the repository at this point in the history
…ctor (#958)

* add failing test case

* [CodingStyle] Skip inside other statement on NewlineAfterStatementRector

* phpstan

* eol

* rename fixture

Co-authored-by: Dominik Peters <d.peters@billiger-mietwagen.de>
  • Loading branch information
samsonasik and Dominik Peters committed Oct 5, 2021
1 parent ed80bec commit e9e2877
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\Stmt\NewlineAfterStatementRector\Fixture;

class SomeClass
{
}

final class SomeOtherClassClass
{
public function getSomeClass(): SomeClass
{
return new class('foobar') extends SomeClass {
};
}
}
11 changes: 11 additions & 0 deletions rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$node = $this->resolveCurrentStatement($node);

if (! in_array($node::class, self::STMTS_TO_HAVE_NEXT_NEWLINE, true)) {
return null;
}
Expand Down Expand Up @@ -159,6 +161,15 @@ public function refactor(Node $node): ?Node
return $node;
}

private function resolveCurrentStatement(Stmt $stmt): Stmt
{
$currentStatement = $stmt->getAttribute(AttributeKey::CURRENT_STATEMENT);

return $currentStatement instanceof Stmt
? $currentStatement
: $stmt;
}

/**
* @param null|Doc[] $comments
*/
Expand Down

0 comments on commit e9e2877

Please sign in to comment.