fix for 32-bit where large value are converted to float
(cherry picked from commit 0d0909e4e6)
70 lines
2.4 KiB
Diff
70 lines
2.4 KiB
Diff
From d07774e18e532336361f2b59c039099fae512898 Mon Sep 17 00:00:00 2001
|
|
From: Remi Collet <remi@remirepo.net>
|
|
Date: Wed, 20 Feb 2019 14:52:09 +0100
|
|
Subject: [PATCH 1/2] fix for 32-bit where large value are converted to float
|
|
|
|
---
|
|
src/Timer.php | 4 ++--
|
|
tests/TimerTest.php | 2 +-
|
|
2 files changed, 3 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/src/Timer.php b/src/Timer.php
|
|
index 8f919b6..9ad76dc 100644
|
|
--- a/src/Timer.php
|
|
+++ b/src/Timer.php
|
|
@@ -44,7 +44,7 @@ public static function stop(): float
|
|
return \microtime(true) - \array_pop(self::$startTimes);
|
|
}
|
|
|
|
- public static function bytesToString(int $bytes): string
|
|
+ public static function bytesToString(float $bytes): string
|
|
{
|
|
foreach (self::$sizes as $unit => $value) {
|
|
if ($bytes >= $value) {
|
|
@@ -54,7 +54,7 @@ public static function bytesToString(int $bytes): string
|
|
}
|
|
}
|
|
|
|
- return $bytes . ' byte' . ($bytes !== 1 ? 's' : '');
|
|
+ return $bytes . ' byte' . ((int)$bytes !== 1 ? 's' : '');
|
|
}
|
|
|
|
public static function secondsToTimeString(float $time): string
|
|
diff --git a/tests/TimerTest.php b/tests/TimerTest.php
|
|
index e8cf7ef..93cc474 100644
|
|
--- a/tests/TimerTest.php
|
|
+++ b/tests/TimerTest.php
|
|
@@ -112,7 +112,7 @@ public function secondsProvider(): array
|
|
/**
|
|
* @dataProvider bytesProvider
|
|
*/
|
|
- public function testCanFormatBytesAsString(string $string, int $bytes): void
|
|
+ public function testCanFormatBytesAsString(string $string, float $bytes): void
|
|
{
|
|
$this->assertEquals($string, Timer::bytesToString($bytes));
|
|
}
|
|
|
|
From 9398c85d883eec73ab9fddb4d72d42091425791b Mon Sep 17 00:00:00 2001
|
|
From: Remi Collet <remi@remirepo.net>
|
|
Date: Wed, 20 Feb 2019 15:02:00 +0100
|
|
Subject: [PATCH 2/2] simplify code
|
|
|
|
---
|
|
src/Timer.php | 4 +---
|
|
1 file changed, 1 insertion(+), 3 deletions(-)
|
|
|
|
diff --git a/src/Timer.php b/src/Timer.php
|
|
index 9ad76dc..c78a6ee 100644
|
|
--- a/src/Timer.php
|
|
+++ b/src/Timer.php
|
|
@@ -48,9 +48,7 @@ public static function bytesToString(float $bytes): string
|
|
{
|
|
foreach (self::$sizes as $unit => $value) {
|
|
if ($bytes >= $value) {
|
|
- $size = \sprintf('%.2f', $bytes >= 1024 ? $bytes / $value : $bytes);
|
|
-
|
|
- return $size . ' ' . $unit;
|
|
+ return \sprintf('%.2f %s', $bytes >= 1024 ? $bytes / $value : $bytes, $unit);
|
|
}
|
|
}
|
|
|