Skip to content

Commit fe3895a

Browse files
committed
RangeFunctionReturnTypeExtension - fix internal ValueError
1 parent 7ef210c commit fe3895a

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/Type/Php/RangeFunctionReturnTypeExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
6565
continue;
6666
}
6767

68+
$rangeSpanned = abs($endConstant->getValue() - $startConstant->getValue());
69+
if ($rangeSpanned <= $stepConstant->getValue()) {
70+
continue;
71+
}
72+
6873
$rangeValues = range($startConstant->getValue(), $endConstant->getValue(), $stepConstant->getValue());
6974
if (count($rangeValues) > self::RANGE_LENGTH_THRESHOLD) {
7075
if ($startConstant instanceof ConstantIntegerType && $endConstant instanceof ConstantIntegerType) {

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,12 @@ public function testBug10979(): void
13481348
$this->assertNoErrors($errors);
13491349
}
13501350

1351+
public function testBug11026(): void
1352+
{
1353+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-11026.php');
1354+
$this->assertNoErrors($errors);
1355+
}
1356+
13511357
/**
13521358
* @param string[]|null $allAnalysedFiles
13531359
* @return Error[]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Bug11026;
4+
5+
function (): void {
6+
$a = range(1, 3/2);
7+
};

0 commit comments

Comments
 (0)