From ebf76f526ffc796446ffd2f8b34b3abb6fbe0045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1?= Date: Wed, 9 Apr 2025 15:54:52 +0200 Subject: [PATCH] IntType fix --- src/IntType.php | 2 +- tests/IntTypeTest.phpt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/IntType.php b/src/IntType.php index 05f08df..404ef47 100644 --- a/src/IntType.php +++ b/src/IntType.php @@ -17,7 +17,7 @@ final public static function from( return (int) $value; } - if (Validators::isNumeric($value) && (int) $value === (int) \ceil(\abs((float) $value))) { + if (Validators::isNumeric($value) && \abs((int) $value) === (int) \ceil(\abs((float) $value))) { return (int) $value; } diff --git a/tests/IntTypeTest.phpt b/tests/IntTypeTest.phpt index fc2e376..df218ff 100644 --- a/tests/IntTypeTest.phpt +++ b/tests/IntTypeTest.phpt @@ -45,6 +45,9 @@ final class IntTypeTest extends TestCase '1', 1.000_00, '1.00000', + -1, + -1.0, + '-1.0', ]; foreach ($invalid as $value) {