Skip to content

Commit cb0cd1c

Browse files
committed
Fix range()
1 parent 35ff689 commit cb0cd1c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Type/Php/RangeFunctionReturnTypeExtension.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use PHPStan\Type\Type;
2323
use PHPStan\Type\TypeCombinator;
2424
use PHPStan\Type\UnionType;
25-
use function abs;
25+
use ValueError;
2626
use function count;
2727
use function range;
2828

@@ -66,12 +66,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
6666
continue;
6767
}
6868

69-
$rangeSpanned = abs($endConstant->getValue() - $startConstant->getValue());
70-
if ($rangeSpanned <= $stepConstant->getValue()) {
69+
try {
70+
$rangeValues = range($startConstant->getValue(), $endConstant->getValue(), $stepConstant->getValue());
71+
} catch (ValueError) {
7172
continue;
7273
}
73-
74-
$rangeValues = range($startConstant->getValue(), $endConstant->getValue(), $stepConstant->getValue());
7574
if (count($rangeValues) > self::RANGE_LENGTH_THRESHOLD) {
7675
if ($startConstant instanceof ConstantIntegerType && $endConstant instanceof ConstantIntegerType) {
7776
if ($startConstant->getValue() > $endConstant->getValue()) {

0 commit comments

Comments
 (0)