Skip to content

Commit

Permalink
Fix range()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 15, 2024
1 parent 35ff689 commit cb0cd1c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Type/Php/RangeFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\UnionType;
use function abs;
use ValueError;
use function count;
use function range;

Expand Down Expand Up @@ -66,12 +66,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
continue;
}

$rangeSpanned = abs($endConstant->getValue() - $startConstant->getValue());
if ($rangeSpanned <= $stepConstant->getValue()) {
try {
$rangeValues = range($startConstant->getValue(), $endConstant->getValue(), $stepConstant->getValue());
} catch (ValueError) {
continue;
}

$rangeValues = range($startConstant->getValue(), $endConstant->getValue(), $stepConstant->getValue());
if (count($rangeValues) > self::RANGE_LENGTH_THRESHOLD) {
if ($startConstant instanceof ConstantIntegerType && $endConstant instanceof ConstantIntegerType) {
if ($startConstant->getValue() > $endConstant->getValue()) {
Expand Down

0 comments on commit cb0cd1c

Please sign in to comment.