Completed
Push — master ( 28afa9...69e2c3 )
by JHONATAN
02:50
created

ClientFactory::addClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 5
crap 2
1
<?php
2
3
namespace Vox\Webservice\Factory;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Handler\CurlHandler;
7
use GuzzleHttp\HandlerStack;
8
use Vox\Webservice\ClientRegistryInterface;
9
10
class ClientFactory
11
{
12 1
    public function addClient(
13
        string $name,
14
        string $baseUri,
15
        ClientRegistryInterface $clientRegistry,
16
        array $defaults = [],
17
        array $middlewares = []
18
    ) {
19 1
        $handlerStack = new HandlerStack(new CurlHandler());
20
21 1
        foreach ($middlewares as $middleware) {
22 1
            $handlerStack->push($middleware);
23
        }
24
25 1
        $clientRegistry->set(
26 1
            $name,
27 1
            new Client(['base_uri' => $baseUri, 'defaults' => $defaults, 'handler' => $handlerStack])
28
        );
29
    }
30
}