|
40 | 40 | use PHPStan\Type\Type;
|
41 | 41 | use PHPStan\Type\TypeCombinator;
|
42 | 42 | use PHPStan\Type\TypeUtils;
|
| 43 | +use PHPStan\Type\TypeWithClassName; |
43 | 44 | use ReflectionObject;
|
44 | 45 | use Traversable;
|
45 | 46 | use function array_key_exists;
|
@@ -335,25 +336,33 @@ private static function getExpressionResolvers(): array
|
335 | 336 | },
|
336 | 337 | 'isInstanceOf' => static function (Scope $scope, Arg $expr, Arg $class): ?Expr {
|
337 | 338 | $classType = $scope->getType($class->value);
|
338 |
| - if (!$classType instanceof ConstantStringType) { |
| 339 | + if ($classType instanceof ConstantStringType) { |
| 340 | + $className = new Name($classType->getValue()); |
| 341 | + } elseif ($classType instanceof TypeWithClassName) { |
| 342 | + $className = new Name($classType->getClassName()); |
| 343 | + } else { |
339 | 344 | return null;
|
340 | 345 | }
|
341 | 346 |
|
342 | 347 | return new Instanceof_(
|
343 | 348 | $expr->value,
|
344 |
| - new Name($classType->getValue()) |
| 349 | + $className |
345 | 350 | );
|
346 | 351 | },
|
347 | 352 | 'notInstanceOf' => static function (Scope $scope, Arg $expr, Arg $class): ?Expr {
|
348 | 353 | $classType = $scope->getType($class->value);
|
349 |
| - if (!$classType instanceof ConstantStringType) { |
| 354 | + if ($classType instanceof ConstantStringType) { |
| 355 | + $className = new Name($classType->getValue()); |
| 356 | + } elseif ($classType instanceof TypeWithClassName) { |
| 357 | + $className = new Name($classType->getClassName()); |
| 358 | + } else { |
350 | 359 | return null;
|
351 | 360 | }
|
352 | 361 |
|
353 | 362 | return new BooleanNot(
|
354 | 363 | new Instanceof_(
|
355 | 364 | $expr->value,
|
356 |
| - new Name($classType->getValue()) |
| 365 | + $className |
357 | 366 | )
|
358 | 367 | );
|
359 | 368 | },
|
@@ -639,11 +648,15 @@ static function (Type $type): Type {
|
639 | 648 |
|
640 | 649 | if ($methodName === 'allNotInstanceOf') {
|
641 | 650 | $classType = $scope->getType($node->getArgs()[1]->value);
|
642 |
| - if (!$classType instanceof ConstantStringType) { |
| 651 | + |
| 652 | + if ($classType instanceof ConstantStringType) { |
| 653 | + $objectType = new ObjectType($classType->getValue()); |
| 654 | + } elseif ($classType instanceof TypeWithClassName) { |
| 655 | + $objectType = new ObjectType($classType->getClassName()); |
| 656 | + } else { |
643 | 657 | return new SpecifiedTypes([], []);
|
644 | 658 | }
|
645 | 659 |
|
646 |
| - $objectType = new ObjectType($classType->getValue()); |
647 | 660 | return $this->arrayOrIterable(
|
648 | 661 | $scope,
|
649 | 662 | $node->getArgs()[0]->value,
|
|
0 commit comments