| Total Complexity | 2 |
| Total Lines | 13 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | final class BytesFormatter implements IBytesFormatter |
||
| 10 | { |
||
| 11 | private const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB']; // 'EB' is max for int on 64-bit systems |
||
| 12 | |||
| 13 | public function format(int $bytes): string |
||
| 14 | { |
||
| 15 | $i = (int)floor(log($bytes, 1024)); |
||
| 16 | return round($bytes / (1024 ** $i), 2) . self::getUnits($i); |
||
| 17 | } |
||
| 18 | |||
| 19 | private static function getUnits(int $i): string |
||
| 22 | } |
||
| 23 | } |
||
| 24 |