|
12 | 12 | use PHPStan\Type\Constant\ConstantBooleanType; |
13 | 13 | use PHPStan\Type\DynamicMethodReturnTypeExtension; |
14 | 14 | use PHPStan\Type\NeverType; |
| 15 | +use PHPStan\Type\ObjectType; |
15 | 16 | use PHPStan\Type\Type; |
16 | 17 | use PHPStan\Type\TypeCombinator; |
17 | 18 | use Throwable; |
@@ -41,7 +42,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool |
41 | 42 | public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type |
42 | 43 | { |
43 | 44 | $args = $methodCall->getArgs(); |
44 | | - if (count($methodCall->getArgs()) < 1) { |
| 45 | + if (count($args) < 1) { |
45 | 46 | return null; |
46 | 47 | } |
47 | 48 |
|
@@ -79,9 +80,19 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method |
79 | 80 |
|
80 | 81 | return null; |
81 | 82 | } elseif ($hasDateTime) { |
82 | | - $variant = ParametersAcceptorSelector::selectFromArgs($scope, $args, $methodReflection->getVariants()); |
| 83 | + $callerType = $scope->getType($methodCall->var); |
83 | 84 |
|
84 | | - return TypeCombinator::remove($variant->getReturnType(), new ConstantBooleanType(false)); |
| 85 | + $dateTimeInterfaceType = new ObjectType(DateTimeInterface::class); |
| 86 | + if ($dateTimeInterfaceType->isSuperTypeOf($callerType)->yes()) { |
| 87 | + return $callerType; |
| 88 | + } |
| 89 | + foreach ($callerType->getObjectClassNames() as $className) { |
| 90 | + if (!$dateTimeInterfaceType->isSuperTypeOf(new ObjectType($className))->yes()) { |
| 91 | + $callerType = TypeCombinator::remove($callerType, new ObjectType($className)); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + return $callerType; |
85 | 96 | } |
86 | 97 |
|
87 | 98 | if ($this->phpVersion->hasDateTimeExceptions()) { |
|
0 commit comments