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