|
8 | 8 | use PHPStan\Analyser\Scope; |
9 | 9 | use PHPStan\Php\PhpVersion; |
10 | 10 | use PHPStan\Reflection\MethodReflection; |
| 11 | +use PHPStan\Reflection\ParametersAcceptorSelector; |
11 | 12 | use PHPStan\Type\Constant\ConstantBooleanType; |
12 | 13 | use PHPStan\Type\DynamicMethodReturnTypeExtension; |
13 | 14 | use PHPStan\Type\NeverType; |
14 | | -use PHPStan\Type\ObjectType; |
15 | 15 | use PHPStan\Type\Type; |
16 | 16 | use PHPStan\Type\TypeCombinator; |
17 | 17 | use Throwable; |
@@ -40,11 +40,12 @@ public function isMethodSupported(MethodReflection $methodReflection): bool |
40 | 40 |
|
41 | 41 | public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type |
42 | 42 | { |
| 43 | + $args = $methodCall->getArgs(); |
43 | 44 | if (count($methodCall->getArgs()) < 1) { |
44 | 45 | return null; |
45 | 46 | } |
46 | 47 |
|
47 | | - $valueType = $scope->getType($methodCall->getArgs()[0]->value); |
| 48 | + $valueType = $scope->getType($args[0]->value); |
48 | 49 | $constantStrings = $valueType->getConstantStrings(); |
49 | 50 |
|
50 | 51 | $hasFalse = false; |
@@ -78,10 +79,9 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method |
78 | 79 |
|
79 | 80 | return null; |
80 | 81 | } elseif ($hasDateTime) { |
81 | | - return TypeCombinator::intersect( |
82 | | - $scope->getType($methodCall->var), |
83 | | - new ObjectType(DateTimeInterface::class), |
84 | | - ); |
| 82 | + $variant = ParametersAcceptorSelector::selectFromArgs($scope, $args, $methodReflection->getVariants()); |
| 83 | + |
| 84 | + return TypeCombinator::remove($variant->getReturnType(), new ConstantBooleanType(false)); |
85 | 85 | } |
86 | 86 |
|
87 | 87 | if ($this->phpVersion->hasDateTimeExceptions()) { |
|
0 commit comments