diff --git a/src/Type/Php/HrtimeFunctionReturnTypeExtension.php b/src/Type/Php/HrtimeFunctionReturnTypeExtension.php index 5b4a28b2ec..097fd1a455 100644 --- a/src/Type/Php/HrtimeFunctionReturnTypeExtension.php +++ b/src/Type/Php/HrtimeFunctionReturnTypeExtension.php @@ -7,14 +7,14 @@ use PHPStan\DependencyInjection\AutowiredService; use PHPStan\Reflection\FunctionReflection; use PHPStan\TrinaryLogic; +use PHPStan\Type\BenevolentUnionType; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\DynamicFunctionReturnTypeExtension; use PHPStan\Type\FloatType; -use PHPStan\Type\IntegerType; +use PHPStan\Type\IntegerRangeType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; -use PHPStan\Type\TypeUtils; use function count; #[AutowiredService] @@ -28,8 +28,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { - $arrayType = new ConstantArrayType([new ConstantIntegerType(0), new ConstantIntegerType(1)], [new IntegerType(), new IntegerType()], [2], isList: TrinaryLogic::createYes()); - $numberType = TypeUtils::toBenevolentUnion(TypeCombinator::union(new IntegerType(), new FloatType())); + $arrayType = new ConstantArrayType( + [new ConstantIntegerType(0), new ConstantIntegerType(1)], + [IntegerRangeType::fromInterval(1, null), IntegerRangeType::fromInterval(0, 999999999)], + [2], + isList: TrinaryLogic::createYes(), + ); + $numberType = new BenevolentUnionType([IntegerRangeType::fromInterval(1, null), new FloatType()]); if (count($functionCall->getArgs()) < 1) { return $arrayType; diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index 22f21b50a2..38c8bc5d7c 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -8684,19 +8684,19 @@ public static function dataPhp73Functions(): array 'array_key_last($constantArrayOptionalKeys3)', ], [ - 'array{int, int}', + 'array{int<1, max>, int<0, 999999999>}', '$hrtime1', ], [ - 'array{int, int}', + 'array{int<1, max>, int<0, 999999999>}', '$hrtime2', ], [ - '(float|int)', + '(float|int<1, max>)', '$hrtime3', ], [ - 'array{int, int}|float|int', + 'array{int<1, max>, int<0, 999999999>}|float|int<1, max>', '$hrtime4', ], ];