Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Type/Php/HrtimeFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
];
Expand Down
Loading