Skip to content

Commit 36adf6f

Browse files
committed
register rule
1 parent 7842149 commit 36adf6f

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveEmptyArrayConditionReturnRector\Fixture;
4+
5+
final class AllowAnyType
6+
{
7+
public function run($result)
8+
{
9+
if ($result === []) {
10+
return [];
11+
}
12+
13+
return $result;
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveEmptyArrayConditionReturnRector\Fixture;
22+
23+
final class AllowAnyType
24+
{
25+
public function run($result)
26+
{
27+
return $result;
28+
}
29+
}
30+
31+
?>

rules/DeadCode/Rector/Stmt/RemoveEmptyArrayConditionReturnRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpParser\Node\Expr\Array_;
1010
use PhpParser\Node\Expr\BinaryOp\Equal;
1111
use PhpParser\Node\Expr\BinaryOp\Identical;
12+
use PhpParser\Node\Stmt\If_;
1213
use PhpParser\Node\Stmt\Return_;
1314
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1415
use Rector\Rector\AbstractRector;
@@ -74,7 +75,7 @@ public function refactor(Node $node): ?Node
7475
}
7576

7677
foreach ($node->stmts as $key => $stmt) {
77-
if (! $stmt instanceof Node\Stmt\If_) {
78+
if (! $stmt instanceof If_) {
7879
continue;
7980
}
8081

src/Config/Level/DeadCodeLevel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector;
5454
use Rector\DeadCode\Rector\Return_\RemoveDeadConditionAboveReturnRector;
5555
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
56+
use Rector\DeadCode\Rector\Stmt\RemoveEmptyArrayConditionReturnRector;
5657
use Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;
5758
use Rector\DeadCode\Rector\Switch_\RemoveDuplicatedCaseInSwitchRector;
5859
use Rector\DeadCode\Rector\Ternary\TernaryToBooleanOrFalseToBooleanAndRector;
@@ -124,6 +125,7 @@ final class DeadCodeLevel
124125
RemoveDeadCatchRector::class,
125126
RemoveDeadTryCatchRector::class,
126127
RemoveDeadIfForeachForRector::class,
128+
RemoveEmptyArrayConditionReturnRector::class,
127129
RemoveDeadStmtRector::class,
128130
UnwrapFutureCompatibleIfPhpVersionRector::class,
129131
RemoveParentCallWithoutParentRector::class,

src/Testing/PHPUnit/AbstractLazyTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private function includePreloadFilesAndScoperAutoload(): void
7070
if (! class_exists(Version::class, true) || (int) Version::id() < 12) {
7171
require_once __DIR__ . '/../../../preload.php';
7272
}
73+
7374
// test case in rector split package
7475
} elseif (file_exists(__DIR__ . '/../../../../../../vendor')) {
7576
require_once __DIR__ . '/../../../preload-split-package.php';

0 commit comments

Comments
 (0)