Conditions | 3 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 3 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
23 | 12 | public function asFilesize($bytes) |
|
24 | { |
||
25 | 12 | if ($bytes === null) { |
|
26 | 1 | return $this->nullValue; |
|
27 | } |
||
28 | |||
29 | 11 | $bytes = (int)$bytes; |
|
30 | 11 | if ($bytes < 0) { |
|
31 | 1 | $bytes = 0; |
|
32 | 1 | } |
|
33 | |||
34 | 11 | $factor = floor(strlen($bytes - 1) / 3); |
|
35 | 11 | $decimals = 2; |
|
36 | |||
37 | 11 | return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $this->fileUnits[$factor]; |
|
38 | } |
||
39 | } |
||
40 |