Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
FileSize | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
asString | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** @noinspection PhpUnhandledExceptionInspection */ |
3 | declare(strict_types=1); |
4 | // TODO unit test |
5 | |
6 | class FileSize { |
7 | public static array $units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; |
8 | |
9 | static function asString(int $fileSize): string { |
10 | if ($fileSize == 0) { |
11 | return '-'; |
12 | } |
13 | |
14 | return round($fileSize / pow(1024, ($i = floor(log($fileSize, 1024)))), 2) |
15 | . ' ' . FileSize::$units[$i]; |
16 | } |
17 | } |