Conditions | 3 |
Paths | 3 |
Total Lines | 17 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3 |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
49 | 12 | public static function getBytes($size) |
|
50 | { |
||
51 | 12 | if (is_numeric($size)) { |
|
52 | 10 | return intval($size); |
|
53 | } |
||
54 | |||
55 | 4 | $size = strtolower(trim($size)); |
|
56 | |||
57 | 4 | $numeric = preg_replace('/[^0-9]/', '', $size); |
|
58 | 4 | $unit = str_replace($numeric, '', $size); |
|
59 | |||
60 | 4 | if (isset(self::$units[$unit])) { |
|
61 | 2 | return $numeric * self::$units[$unit]; |
|
62 | } |
||
63 | |||
64 | 2 | throw new \InvalidArgumentException(sprintf('Unknown size format: "%s"', $size)); |
|
65 | } |
||
66 | } |
||
67 |