Skip to content

Commit

Permalink
Prevent warning in range() on php 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed Sep 10, 2024
1 parent 9d9fb56 commit 68f6e25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Type/Php/RangeFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
}

try {
$rangeValues = range($startConstant->getValue(), $endConstant->getValue(), $stepConstant->getValue());
$rangeValues = @range($startConstant->getValue(), $endConstant->getValue(), $stepConstant->getValue());
} catch (ValueError) {
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5685,6 +5685,10 @@ public function dataRangeFunction(): array
'array{2, 4}',
'range(2, 5, 2)',
],
[
'array{2, 0}',
"range(2, '', 2)",
],
[
PHP_VERSION_ID < 80300 ? 'array{2.0, 3.0, 4.0, 5.0}' : 'array{2, 3, 4, 5}',
'range(2, 5, 1.0)',
Expand Down

0 comments on commit 68f6e25

Please sign in to comment.