mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 09:50:49 +00:00
[DeadCode] Ensure has stmts on RemoveDeadInstanceOfRector (#2252)
* [DeadCode] Ensure has stmts on RemoveDeadInstanceOfRector
* Fixed 🎉
* fix
This commit is contained in:
parent
c91f3ad629
commit
3135f29362
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user