From 68f6e25e2a179d947ba58a25217791ee2f01034a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 9 Sep 2024 15:24:38 +0200 Subject: [PATCH] Prevent warning in range() on php 7.x --- src/Type/Php/RangeFunctionReturnTypeExtension.php | 2 +- tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Type/Php/RangeFunctionReturnTypeExtension.php b/src/Type/Php/RangeFunctionReturnTypeExtension.php index 16c7a37788..ed43f64f20 100644 --- a/src/Type/Php/RangeFunctionReturnTypeExtension.php +++ b/src/Type/Php/RangeFunctionReturnTypeExtension.php @@ -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; } diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index 1d17f9ee48..0a9beb6fb8 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -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)',