From 330a2f5b26048ae2acfb17636a59f59e88517664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=B2=A0=5F=E0=B2=A0?= Date: Mon, 12 Dec 2022 18:04:58 +0100 Subject: [PATCH] just return null instead of the default type --- .../Php/DateIntervalDynamicReturnTypeExtension.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Type/Php/DateIntervalDynamicReturnTypeExtension.php b/src/Type/Php/DateIntervalDynamicReturnTypeExtension.php index 1e5d4e7868a..da06b280bce 100644 --- a/src/Type/Php/DateIntervalDynamicReturnTypeExtension.php +++ b/src/Type/Php/DateIntervalDynamicReturnTypeExtension.php @@ -6,12 +6,12 @@ use PhpParser\Node\Expr\StaticCall; use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; -use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\DynamicStaticMethodReturnTypeExtension; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use PHPStan\Type\TypeUtils; class DateIntervalDynamicReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension { @@ -28,16 +28,10 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): ?Type { - $defaultReturnType = ParametersAcceptorSelector::selectFromArgs( - $scope, - $methodCall->getArgs(), - $methodReflection->getVariants(), - )->getReturnType(); - - $dateTimeString = $scope->getType($methodCall->getArgs()[0]->value); + $dateTimeString = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value)); if (!($dateTimeString instanceof ConstantStringType)) { - return $defaultReturnType; + return null; } $isValid = DateInterval::createFromDateString($dateTimeString->getValue()) !== false;