Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions src/Utils/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
4 changes: 2 additions & 2 deletions tests/Utils/Helpers.clamp().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
);