| Conditions | 2 |
| Paths | 1 |
| Total Lines | 10 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 | } |
||
| 51 |