Conditions | 3 |
Paths | 3 |
Total Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
18 | public static function getHumanReadableSize(int $sizeInBytes): string |
||
19 | { |
||
20 | $units = ['B', 'KB', 'MB', 'GB', 'TB']; |
||
21 | |||
22 | if ($sizeInBytes == 0) { |
||
23 | return '0 '.$units[1]; |
||
24 | } |
||
25 | |||
26 | for ($i = 0; $sizeInBytes > 1024; $i++) { |
||
27 | $sizeInBytes /= 1024; |
||
28 | } |
||
29 | |||
30 | return round($sizeInBytes, 2).' '.$units[$i]; |
||
31 | } |
||
32 | |||
40 |