Skip to content

Commit

Permalink
refactor RemoveDeadInstanceOfRector to direct return (#2251)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 7, 2022
1 parent 81ba0c9 commit c91f3ad
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Property;
Expand Down Expand Up @@ -82,8 +83,9 @@ public function getNodeTypes(): array

/**
* @param If_ $node
* @return Stmt[]|null
*/
public function refactor(Node $node): ?If_
public function refactor(Node $node): ?array
{
if (! $this->ifManipulator->isIfWithoutElseAndElseIfs($node)) {
return null;
Expand All @@ -109,7 +111,10 @@ public function refactor(Node $node): ?If_
return null;
}

private function processMayDeadInstanceOf(If_ $if, Instanceof_ $instanceof): ?If_
/**
* @return Stmt[]|null
*/
private function processMayDeadInstanceOf(If_ $if, Instanceof_ $instanceof): ?array
{
if (! $instanceof->class instanceof Name) {
return null;
Expand All @@ -135,12 +140,13 @@ private function processMayDeadInstanceOf(If_ $if, Instanceof_ $instanceof): ?If
return null;
}

$this->removeNode($if);

if ($if->cond === $instanceof) {
$this->nodesToAddCollector->addNodesBeforeNode($if->stmts, $if);
return $if->stmts;
}

$this->removeNode($if);
return $if;
return null;
}

private function shouldSkipFromNotTypedParam(Instanceof_ $instanceof): bool
Expand Down

0 comments on commit c91f3ad

Please sign in to comment.