| Conditions | 5 |
| Paths | 12 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 32 | public static function howManyBytes(int $max, int $min = 0, bool $unsigned = Schema::DEFAULT_INTEGER_UNSIGNED): int |
||
| 33 | { |
||
| 34 | if ($min > $max) { |
||
| 35 | Debug::message('Se ha invocado a howManyBytes con el mínimo y máximo cambiados'); |
||
| 36 | $tmp = $min; |
||
| 37 | $min = $max; |
||
| 38 | $max = $tmp; |
||
| 39 | } |
||
| 40 | |||
| 41 | $bits = log($max + 1, 2); |
||
| 42 | if (!$unsigned) { |
||
| 43 | $bits++; |
||
| 44 | } |
||
| 45 | $bytes = ceil($bits / 8); |
||
| 46 | |||
| 47 | if ($min >= 0) { |
||
| 48 | return $bytes; |
||
|
|
|||
| 49 | } |
||
| 50 | |||
| 51 | $bits = log(abs($min), 2); |
||
| 52 | $bytesForMin = ceil(($bits + 1) / 8); |
||
| 53 | if ($bytesForMin > $bytes) { |
||
| 54 | return $bytesForMin; |
||
| 55 | } |
||
| 56 | |||
| 57 | return $bytes; |
||
| 58 | } |
||
| 60 |