Format   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getReadableSize() 0 7 1
A getReadableTime() 0 14 3
1
<?php
2
3
/**
4
 * Simple utility class to format times and sizes
5
 */
6
namespace Rocket\Utilities;
7
8
/**
9
 * Simple utility class to format times and sizes
10
 */
11
class Format
12
{
13
    /**
14
     * Get file size with correct extension
15
     *
16
     * @param int $bytes
17
     * @return string
18
     */
19 9
    public static function getReadableSize($bytes)
20
    {
21 9
        $unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
22 9
        $exp = floor(log($bytes, 1024)) | 0;
23
24 9
        return round($bytes / (pow(1024, $exp)), 2) . " $unit[$exp]";
25
    }
26
27
    /**
28
     * Format time
29
     *
30
     * @param int $time
31
     * @return string
32
     */
33 9
    public static function getReadableTime($time)
34
    {
35 9
        if ($time < 1000) {
36 3
            return "{$time}ms";
37
        }
38
39 6
        $prefix = '';
40 6
        if ($time >= 60000) {
41 3
            $prefix = floor($time / 60000) . 'm ';
42 3
            $time = $time % 60000;
43 3
        }
44
45 6
        return $prefix . number_format((float) ($time / 1000), 3, '.', '') . 's';
46
    }
47
}
48