Conditions | 5 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 5.0342 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
30 | public function createClient(array $config = []): ClientInterface |
||
31 | 1 | { |
|
32 | 1 | if (! class_exists(Client::class)) { |
|
33 | 1 | throw new LogicException('To use the Curl client you need to install the "php-http/curl-client" package.'); |
|
34 | } |
||
35 | |||
36 | // Try to resolve curl constant names |
||
37 | foreach ($config as $key => $value) { |
||
38 | // If the $key is a string we assume it is a constant |
||
39 | if (! is_string($key)) { |
||
40 | 1 | continue; |
|
41 | } |
||
42 | 1 | ||
43 | if (null === ($constantValue = constant($key))) { |
||
44 | throw new LogicException(sprintf('Key %s is not an int nor a CURL constant', $key)); |
||
45 | } |
||
46 | |||
47 | 1 | unset($config[$key]); |
|
48 | $config[$constantValue] = $value; |
||
49 | 1 | } |
|
50 | 1 | ||
51 | return new Client($this->responseFactory, $this->streamFactory, $config); |
||
52 | } |
||
54 |