|
49 | 49 | use ReflectionObject;
|
50 | 50 | use Traversable;
|
51 | 51 | use function array_key_exists;
|
| 52 | +use function array_map; |
52 | 53 | use function array_reduce;
|
53 | 54 | use function array_shift;
|
54 | 55 | use function count;
|
@@ -407,33 +408,37 @@ private function getExpressionResolvers(): array
|
407 | 408 | },
|
408 | 409 | 'isInstanceOf' => static function (Scope $scope, Arg $expr, Arg $class): ?Expr {
|
409 | 410 | $classType = $scope->getType($class->value);
|
410 |
| - $classNameStrings = $classType->getConstantStrings(); |
411 |
| - if (count($classNameStrings) !== 1) { |
412 |
| - $classNames = $classType->getObjectClassNames(); |
413 |
| - if (count($classNames) === 1) { |
414 |
| - return new Instanceof_( |
415 |
| - $expr->value, |
416 |
| - new Name($classNames[0]) |
417 |
| - ); |
418 |
| - } |
419 |
| - return null; |
| 411 | + $classNames = $classType->getObjectTypeOrClassStringObjectType()->getObjectClassNames(); |
| 412 | + |
| 413 | + if (count($classNames) !== 0) { |
| 414 | + return self::implodeExpr(array_map(static function (string $className) use ($expr): Expr { |
| 415 | + return new Instanceof_($expr->value, new Name($className)); |
| 416 | + }, $classNames), BooleanOr::class); |
420 | 417 | }
|
421 | 418 |
|
422 |
| - return new Instanceof_( |
423 |
| - $expr->value, |
424 |
| - new Name($classNameStrings[0]->getValue()) |
| 419 | + return new FuncCall( |
| 420 | + new Name('is_object'), |
| 421 | + [$expr] |
425 | 422 | );
|
426 | 423 | },
|
427 | 424 | 'isInstanceOfAny' => function (Scope $scope, Arg $expr, Arg $classes): ?Expr {
|
428 | 425 | return self::buildAnyOfExpr($scope, $expr, $classes, $this->resolvers['isInstanceOf']);
|
429 | 426 | },
|
430 |
| - 'notInstanceOf' => function (Scope $scope, Arg $expr, Arg $class): ?Expr { |
431 |
| - $expr = $this->resolvers['isInstanceOf']($scope, $expr, $class); |
432 |
| - if ($expr === null) { |
433 |
| - return null; |
| 427 | + 'notInstanceOf' => static function (Scope $scope, Arg $expr, Arg $class): ?Expr { |
| 428 | + $classType = $scope->getType($class->value); |
| 429 | + $classNames = $classType->getObjectTypeOrClassStringObjectType()->getObjectClassNames(); |
| 430 | + |
| 431 | + if (count($classNames) !== 0) { |
| 432 | + $result = self::implodeExpr(array_map(static function (string $className) use ($expr): Expr { |
| 433 | + return new Instanceof_($expr->value, new Name($className)); |
| 434 | + }, $classNames), BooleanOr::class); |
| 435 | + |
| 436 | + if ($result !== null) { |
| 437 | + return new BooleanNot($result); |
| 438 | + } |
434 | 439 | }
|
435 | 440 |
|
436 |
| - return new BooleanNot($expr); |
| 441 | + return null; |
437 | 442 | },
|
438 | 443 | 'isAOf' => static function (Scope $scope, Arg $expr, Arg $class): Expr {
|
439 | 444 | $exprType = $scope->getType($expr->value);
|
|
0 commit comments