diff --git a/rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php b/rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php index 79bfa6090fb..1762aab02de 100644 --- a/rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php +++ b/rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php @@ -13,12 +13,14 @@ use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; use PhpParser\NodeTraverser; use PHPStan\Reflection\ClassReflection; use PHPStan\Type\MixedType; +use PHPStan\Type\ObjectType; use Rector\NodeManipulator\IfManipulator; use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; @@ -140,12 +142,15 @@ private function isInstanceofTheSameType(Instanceof_ $instanceof) : ?bool if ($classReflection instanceof ClassReflection && $classReflection->isTrait()) { return null; } - $classType = $this->nodeTypeResolver->getType($instanceof->class); + if (!$instanceof->class instanceof FullyQualified) { + return null; + } $exprType = $this->nodeTypeResolver->getNativeType($instanceof->expr); - if ($classType->equals($exprType)) { - return \true; + if (!$exprType instanceof ObjectType) { + return null; } - return $classType->isSuperTypeOf($exprType)->yes(); + $className = $instanceof->class->toString(); + return $exprType->isInstanceOf($className)->yes(); } private function refactorIfWithBooleanAnd(If_ $if) : ?\PhpParser\Node\Stmt\If_ { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index eaa1f9bd70b..7e69482826f 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'de0dda8f29453b36bcfa3728cf26662fb634fcd1'; + public const PACKAGE_VERSION = '0482641eaf933bdb7ef52a89f7064126b61366c3'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-06-30 19:47:13'; + public const RELEASE_DATE = '2024-06-30 19:47:32'; /** * @var int */