Skip to content

Commit eca59d0

Browse files
committed
More precise hrtime() return type
1 parent e4e21c7 commit eca59d0

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Type/Php/HrtimeFunctionReturnTypeExtension.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
use PHPStan\DependencyInjection\AutowiredService;
88
use PHPStan\Reflection\FunctionReflection;
99
use PHPStan\TrinaryLogic;
10+
use PHPStan\Type\BenevolentUnionType;
1011
use PHPStan\Type\Constant\ConstantArrayType;
1112
use PHPStan\Type\Constant\ConstantIntegerType;
1213
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
1314
use PHPStan\Type\FloatType;
14-
use PHPStan\Type\IntegerType;
15+
use PHPStan\Type\IntegerRangeType;
1516
use PHPStan\Type\Type;
1617
use PHPStan\Type\TypeCombinator;
17-
use PHPStan\Type\TypeUtils;
1818
use function count;
1919

2020
#[AutowiredService]
@@ -28,8 +28,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
2828

2929
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3030
{
31-
$arrayType = new ConstantArrayType([new ConstantIntegerType(0), new ConstantIntegerType(1)], [new IntegerType(), new IntegerType()], [2], isList: TrinaryLogic::createYes());
32-
$numberType = TypeUtils::toBenevolentUnion(TypeCombinator::union(new IntegerType(), new FloatType()));
31+
$arrayType = new ConstantArrayType(
32+
[new ConstantIntegerType(0), new ConstantIntegerType(1)],
33+
[IntegerRangeType::fromInterval(1, null), IntegerRangeType::fromInterval(0, 999999999)],
34+
[2],
35+
isList: TrinaryLogic::createYes(),
36+
);
37+
$numberType = new BenevolentUnionType([IntegerRangeType::fromInterval(1, null), new FloatType()]);
3338

3439
if (count($functionCall->getArgs()) < 1) {
3540
return $arrayType;

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8684,19 +8684,19 @@ public static function dataPhp73Functions(): array
86848684
'array_key_last($constantArrayOptionalKeys3)',
86858685
],
86868686
[
8687-
'array{int, int}',
8687+
'array{int<1, max>, int<0, 999999999>}',
86888688
'$hrtime1',
86898689
],
86908690
[
8691-
'array{int, int}',
8691+
'array{int<1, max>, int<0, 999999999>}',
86928692
'$hrtime2',
86938693
],
86948694
[
8695-
'(float|int)',
8695+
'(float|int<1, max>)',
86968696
'$hrtime3',
86978697
],
86988698
[
8699-
'array{int, int}|float|int',
8699+
'array{int<1, max>, int<0, 999999999>}|float|int<1, max>',
87008700
'$hrtime4',
87018701
],
87028702
];

0 commit comments

Comments
 (0)