Skip to content

Commit 7ee4cf5

Browse files
committed
Util\Timing::getHumanReadableDuration: magic numbers to constants
Make the code more self-descriptive and use less "magic numbers" by declaring a couple of constants.
1 parent a3f31a9 commit 7ee4cf5

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/Util/Timing.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@
1212
class Timing
1313
{
1414

15+
/**
16+
* Number of milliseconds in a minute.
17+
*
18+
* @var int
19+
*/
20+
const MINUTE_IN_MS = 60000;
21+
22+
/**
23+
* Number of milliseconds in a second.
24+
*
25+
* @var int
26+
*/
27+
const SECOND_IN_MS = 1000;
28+
1529
/**
1630
* The start time of the run in microseconds.
1731
*
@@ -67,15 +81,15 @@ public static function getDuration()
6781
public static function getHumanReadableDuration($duration)
6882
{
6983
$timeString = '';
70-
if ($duration >= 60000) {
71-
$mins = floor($duration / 60000);
72-
$secs = round((fmod($duration, 60000) / 1000), 2);
84+
if ($duration >= self::MINUTE_IN_MS) {
85+
$mins = floor($duration / self::MINUTE_IN_MS);
86+
$secs = round((fmod($duration, self::MINUTE_IN_MS) / self::SECOND_IN_MS), 2);
7387
$timeString = $mins.' mins';
7488
if ($secs >= 0.01) {
7589
$timeString .= ", $secs secs";
7690
}
77-
} else if ($duration >= 1000) {
78-
$timeString = round(($duration / 1000), 2).' secs';
91+
} else if ($duration >= self::SECOND_IN_MS) {
92+
$timeString = round(($duration / self::SECOND_IN_MS), 2).' secs';
7993
} else {
8094
$timeString = round($duration).'ms';
8195
}

0 commit comments

Comments
 (0)