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

[CodingStyle] Add more statements for NewlineAfterStatementRector #792

Merged
merged 2 commits into from
Aug 30, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace A
{
class C
{
}
class D
{
}
}
namespace B
{
interface E
{
}
trait F
{
}
class G implements E
{
use F;
}
}

?>
-----
<?php

namespace A
{
class C
{
}

class D
{
}
}

namespace B
{
interface E
{
}

trait F
{
}

class G implements E
{
use F;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

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

function run()
{
try {

} catch (Exception $e) {

}
return true;
}

?>
-----
<?php

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

function run()
{
try {

} catch (Exception $e) {

}

return true;
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

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

function run($data)
{
switch ($data) {
case 'a':
echo 'test';
break;
default:
echo 'test 1';
}
return true;
}

?>
-----
<?php

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

function run($data)
{
switch ($data) {
case 'a':
echo 'test';
break;
default:
echo 'test 1';
}

return true;
}

?>
12 changes: 12 additions & 0 deletions rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@

use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Do_;
use PhpParser\Node\Stmt\For_;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Switch_;
use PhpParser\Node\Stmt\Trait_;
use PhpParser\Node\Stmt\TryCatch;
use PhpParser\Node\Stmt\While_;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand All @@ -39,6 +45,12 @@ final class NewlineAfterStatementRector extends AbstractRector
While_::class,
For_::class,
ClassConst::class,
Namespace_::class,
TryCatch::class,
Class_::class,
Trait_::class,
Interface_::class,
Switch_::class,
];

/**
Expand Down