|
9 | 9 | use PhpParser\Node\Expr\BooleanNot; |
10 | 10 | use PhpParser\Node\Expr\Empty_; |
11 | 11 | use PhpParser\Node\Expr\Instanceof_; |
12 | | -use PhpParser\Node\Name; |
13 | 12 | use PHPStan\Type\ObjectType; |
14 | 13 | use PHPStan\Type\TypeCombinator; |
15 | 14 | use PHPStan\Type\UnionType; |
| 15 | +use Rector\PhpParser\Node\NullableObjectToInstanceofFactory; |
16 | 16 | use Rector\PHPStan\ScopeFetcher; |
17 | | -use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; |
18 | 17 | use Rector\Rector\AbstractRector; |
19 | 18 | use Rector\RuleDoc\CodeSample\CodeSample; |
20 | 19 | use Rector\RuleDoc\RuleDefinition; |
21 | | -use Rector\StaticTypeMapper\StaticTypeMapper; |
22 | 20 |
|
23 | 21 | /** |
24 | 22 | * @see \Rector\Tests\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector\EmptyOnNullableObjectToInstanceOfRectorTest |
25 | 23 | */ |
26 | 24 | final class EmptyOnNullableObjectToInstanceOfRector extends AbstractRector |
27 | 25 | { |
28 | 26 | public function __construct( |
29 | | - private readonly StaticTypeMapper $staticTypeMapper |
| 27 | + private readonly NullableObjectToInstanceofFactory $nullableObjectToInstanceofFactory |
30 | 28 | ) { |
31 | 29 | } |
32 | 30 |
|
@@ -107,17 +105,6 @@ public function refactor(Node $node): null|Instanceof_|BooleanNot |
107 | 105 | return null; |
108 | 106 | } |
109 | 107 |
|
110 | | - $objectType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($exprType, TypeKind::RETURN); |
111 | | - if (! $objectType instanceof Name) { |
112 | | - return null; |
113 | | - } |
114 | | - |
115 | | - $instanceof = new Instanceof_($empty->expr, $objectType); |
116 | | - |
117 | | - if ($isNegated) { |
118 | | - return $instanceof; |
119 | | - } |
120 | | - |
121 | | - return new BooleanNot($instanceof); |
| 108 | + return $this->nullableObjectToInstanceofFactory->create($empty->expr, $exprType, ! $isNegated); |
122 | 109 | } |
123 | 110 | } |
0 commit comments