| Total Complexity | 14 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class CurlOptionNormalizer |
||
| 6 | { |
||
| 7 | protected static $strToInt = []; |
||
| 8 | protected static $intToStr = []; |
||
| 9 | |||
| 10 | 2 | public static function stringify($key) |
|
| 11 | 2 | { |
|
| 12 | 2 | static::initialize(); |
|
| 13 | 2 | if (is_int($key)) { |
|
| 14 | 2 | if (!isset(static::$intToStr[$key])) { |
|
| 15 | 2 | throw new \DomainException('Invalid cURL option number: ' . $key); |
|
| 16 | } |
||
| 17 | 2 | return static::$intToStr[$key]; |
|
| 18 | }; |
||
| 19 | 1 | if (!isset(static::$strToInt[$key])) { |
|
| 20 | 1 | throw new \DomainException('Invalid cURL option name: ' . $key); |
|
| 21 | } |
||
| 22 | 1 | return $key; |
|
| 23 | } |
||
| 24 | |||
| 25 | 15 | public static function numerify($key) |
|
| 26 | 15 | { |
|
| 27 | 15 | static::initialize(); |
|
| 28 | 15 | if (is_string($key)) { |
|
| 29 | 2 | if (!isset(static::$strToInt[$key])) { |
|
| 30 | 2 | throw new \DomainException('Invalid cURL option name: ' . $key); |
|
| 31 | } |
||
| 32 | 2 | return static::$strToInt[$key]; |
|
| 33 | }; |
||
| 34 | 14 | if (!isset(static::$intToStr[$key])) { |
|
| 35 | 1 | throw new \DomainException('Invalid cURL option number: ' . $key); |
|
| 36 | } |
||
| 37 | 14 | return $key; |
|
| 38 | } |
||
| 39 | |||
| 40 | 1 | public static function stringifyAll(array $options) |
|
| 41 | 1 | { |
|
| 42 | 1 | $r = []; |
|
| 43 | 1 | foreach ($options as $key => $value) { |
|
| 44 | 1 | $r[static::stringify($key)] = $value; |
|
| 45 | } |
||
| 46 | 1 | return $r; |
|
| 47 | } |
||
| 48 | |||
| 49 | 69 | public static function numerifyAll(array $options) |
|
| 50 | 69 | { |
|
| 51 | 69 | $r = []; |
|
| 52 | 69 | foreach ($options as $key => $value) { |
|
| 53 | 14 | $r[static::numerify($key)] = $value; |
|
| 54 | } |
||
| 55 | 69 | return $r; |
|
| 56 | } |
||
| 57 | |||
| 58 | 17 | protected static function initialize() |
|
| 63 | } |
||
| 64 | 17 | } |
|
| 65 | } |
||
| 66 |