| Conditions | 5 |
| Paths | 5 |
| Total Lines | 21 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 4 |
| CRAP Score | 10.3999 |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | 5 | public function createClient(array $config = []) |
|
| 38 | { |
||
| 39 | 5 | if (!class_exists('Http\Client\Curl\Client')) { |
|
| 40 | throw new \LogicException('To use the Curl client you need to install the "php-http/curl-client" package.'); |
||
| 41 | } |
||
| 42 | |||
| 43 | // Try to resolve curl constant names |
||
| 44 | 5 | foreach ($config as $key => $value) { |
|
| 45 | // If the $key is a string we assume it is a constant |
||
| 46 | if (is_string($key)) { |
||
| 47 | if (null === ($constantValue = constant($key))) { |
||
| 48 | throw new \LogicException(sprintf('Key %s is not an int nor a CURL constant', $key)); |
||
| 49 | } |
||
| 50 | |||
| 51 | unset($config[$key]); |
||
| 52 | $config[$constantValue] = $value; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | 5 | return new Client($this->messageFactory, $this->streamFactory, $config); |
|
| 57 | } |
||
| 58 | } |
||
| 59 |