[DeadCode] Ensure has stmts on RemoveDeadInstanceOfRector (#2252)

* [DeadCode] Ensure has stmts on RemoveDeadInstanceOfRector

* Fixed 🎉

* fix
This commit is contained in:
Abdul Malik Ikhsan 2022-05-07 17:18:33 +07:00 committed by GitHub
parent c91f3ad629
commit 3135f29362
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 7 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\Tests\DeadCode\Rector\If_\RemoveDeadInstanceOfRector\Fixture;
use stdClass;
class NoStmts
{
public function go(stdClass $var)
{
if ($var instanceof stdClass) {
}
}
}
?>
-----
<?php
namespace Rector\Tests\DeadCode\Rector\If_\RemoveDeadInstanceOfRector\Fixture;
use stdClass;
class NoStmts
{
public function go(stdClass $var)
{
}
}
?>

View File

@ -83,9 +83,9 @@ CODE_SAMPLE
/**
* @param If_ $node
* @return Stmt[]|null
* @return Stmt[]|null|If_
*/
public function refactor(Node $node): ?array
public function refactor(Node $node): null|array|If_
{
if (! $this->ifManipulator->isIfWithoutElseAndElseIfs($node)) {
return null;
@ -114,7 +114,7 @@ CODE_SAMPLE
/**
* @return Stmt[]|null
*/
private function processMayDeadInstanceOf(If_ $if, Instanceof_ $instanceof): ?array
private function processMayDeadInstanceOf(If_ $if, Instanceof_ $instanceof): null|array|If_
{
if (! $instanceof->class instanceof Name) {
return null;
@ -140,13 +140,12 @@ CODE_SAMPLE
return null;
}
$this->removeNode($if);
if ($if->cond === $instanceof) {
if ($if->cond === $instanceof && $if->stmts !== []) {
return $if->stmts;
}
return null;
$this->removeNode($if);
return $if;
}
private function shouldSkipFromNotTypedParam(Instanceof_ $instanceof): bool