Conditions | 5 |
Paths | 5 |
Total Lines | 21 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 5 |
CRAP Score | 9.9614 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
37 | 1 | public function createClient(array $config = []) |
|
38 | { |
||
39 | 1 | 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 | 1 | 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 | 1 | } |
|
55 | |||
56 | 1 | return new Client($this->messageFactory, $this->streamFactory, $config); |
|
57 | } |
||
58 | } |
||
59 |