diff --git a/composer.json b/composer.json index 6eb4dd5a..2c266dd9 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ } ], "require": { - "php": "8.2 - 8.5" + "php": "8.2 - 8.5", + "symfony/polyfill-php86": "^1.36" }, "require-dev": { "nette/tester": "^2.5", diff --git a/src/Utils/Helpers.php b/src/Utils/Helpers.php index 73d77bba..c506a447 100644 --- a/src/Utils/Helpers.php +++ b/src/Utils/Helpers.php @@ -65,11 +65,7 @@ public static function falseToNull(mixed $value): mixed */ public static function clamp(int|float $value, int|float $min, int|float $max): int|float { - if ($min > $max) { - throw new Nette\InvalidArgumentException("Minimum ($min) is not less than maximum ($max)."); - } - - return min(max($value, $min), $max); + return clamp($value, $min, $max); } diff --git a/tests/Utils/Helpers.clamp().phpt b/tests/Utils/Helpers.clamp().phpt index 8277f617..f4d3bcfc 100644 --- a/tests/Utils/Helpers.clamp().phpt +++ b/tests/Utils/Helpers.clamp().phpt @@ -14,6 +14,6 @@ Assert::same(19.0, Helpers::clamp(20.0, 10.0, 19.0)); Assert::exception( fn() => Helpers::clamp(20, 30, 10), - InvalidArgumentException::class, - 'Minimum (30) is not less than maximum (10).', + ValueError::class, + 'clamp(): Argument #2 ($min) must be smaller than or equal to argument #3 ($max)', );