diff --git a/src/Type/Php/DateIntervalDynamicReturnTypeExtension.php b/src/Type/Php/DateIntervalDynamicReturnTypeExtension.php index a59b9757463..6d91903ce3e 100644 --- a/src/Type/Php/DateIntervalDynamicReturnTypeExtension.php +++ b/src/Type/Php/DateIntervalDynamicReturnTypeExtension.php @@ -11,6 +11,7 @@ use PHPStan\Type\DynamicStaticMethodReturnTypeExtension; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use x\boo; use function array_map; use function count; use function gettype; @@ -40,21 +41,21 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, $strings = $scope->getType($arguments[0]->value)->getConstantStrings(); - $possibleReturnTypes = array_map( - static fn (ConstantStringType $s): string => gettype(@DateInterval::createFromDateString($s->getValue())), - $strings, - ); + $possibleReturnTypes = []; + foreach($strings as $string) { + $possibleReturnTypes[] = @DateInterval::createFromDateString($string->getValue()) instanceof DateInterval ? DateInterval::class : false; + } // the error case, when wrong types are passed if (count($possibleReturnTypes) === 0) { return null; } - if (in_array('boolean', $possibleReturnTypes, true) && in_array('object', $possibleReturnTypes, true)) { + if (in_array(false, $possibleReturnTypes, true) && in_array(DateInterval::class, $possibleReturnTypes, true)) { return null; } - if (in_array('boolean', $possibleReturnTypes, true)) { + if (in_array(false, $possibleReturnTypes, true)) { return new ConstantBooleanType(false); }