Total Complexity | 5 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 92.31% |
Changes | 0 |
1 | <?php |
||
14 | class Formatter |
||
15 | { |
||
16 | /** |
||
17 | * @param integer $bytes |
||
18 | * @param integer $precision |
||
19 | * @return string |
||
20 | */ |
||
21 | 3 | public static function bytes($bytes, $precision = 2) |
|
22 | { |
||
23 | 3 | $units = ['b', 'KiB', 'MiB', 'GiB', 'TiB']; |
|
24 | |||
25 | 3 | $bytes = max($bytes, 0); |
|
26 | 3 | $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); |
|
27 | 3 | $pow = min($pow, count($units) - 1); |
|
28 | 3 | $bytes /= (1 << (10 * $pow)); |
|
29 | |||
30 | 3 | return round($bytes, $precision) . ' ' . $units[$pow]; |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param mixed $date |
||
35 | * @param string $format |
||
36 | * @return string |
||
37 | */ |
||
38 | 2 | public static function date($date, $format = null) |
|
49 | } |
||
50 | } |
||
51 |