diff --git a/lib/cast_to_int.php b/lib/cast_to_int.php index 138a025..5a57a55 100644 --- a/lib/cast_to_int.php +++ b/lib/cast_to_int.php @@ -49,7 +49,7 @@ function RandomCompat_intval($number, $fail_open = false) if (is_int($number) || is_float($number)) { $number += 0; } elseif (is_numeric($number)) { - $number = (int) $number; + $number += 0; } if ( diff --git a/psalm.xml b/psalm.xml index f9c8cd1..f501315 100644 --- a/psalm.xml +++ b/psalm.xml @@ -8,6 +8,7 @@ + diff --git a/tests/unit/RandomIntTest.php b/tests/unit/RandomIntTest.php index dd96e81..c8cbb0d 100644 --- a/tests/unit/RandomIntTest.php +++ b/tests/unit/RandomIntTest.php @@ -33,8 +33,8 @@ public function testOutput() $this->assertTrue($integers[6] === 0); $this->assertTrue($integers[7] >= $half_neg_max && $integers[7] <= PHP_INT_MAX); $this->assertTrue($integers[8] >= 0 && $integers[8] <= 255); - $this->assertTrue($integers[9] === -4); - $this->assertTrue($integers[10] === 1337000); + $this->assertSame($integers[9], -4); + $this->assertSame($integers[10], 1337000); try { $h = random_int("2147483648", "2147483647");