Conditions | 3 |
Paths | 3 |
Total Lines | 12 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | public static function humanReadableSize(int $sizeInBytes): string |
||
8 | { |
||
9 | $units = ['B', 'KB', 'MB', 'GB', 'TB']; |
||
10 | |||
11 | if ($sizeInBytes === 0) { |
||
12 | return '0 '.$units[1]; |
||
13 | } |
||
14 | for ($i = 0; $sizeInBytes > 1024; $i++) { |
||
15 | $sizeInBytes /= 1024; |
||
16 | } |
||
17 | |||
18 | return round($sizeInBytes, 2).' '.$units[$i]; |
||
19 | } |
||
21 |