Test Failed
Push — develop ( b3c44f...3a55d2 )
by Jens
10:53
created

HttpClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 39
ccs 8
cts 12
cp 0.6667
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A executeAsync() 0 11 3
A execute() 0 11 3
1
<?php
2
3
namespace Commercetools\Core\Client;
4
5
use Commercetools\Core\Request\ClientRequestInterface;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\GuzzleException;
8
use GuzzleHttp\Promise\PromiseInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
class HttpClient extends Client
12
{
13
    /**
14
     * @param ClientRequestInterface $request
15
     * @param array|null $headers
16
     * @param array $options
17
     * @return mixed|ResponseInterface
18
     * @throws GuzzleException
19
     */
20 1
    public function execute(ClientRequestInterface $request, array $headers = null, array $options = [])
21
    {
22 1
        $httpRequest = $request->httpRequest();
23 1
        if (is_array($headers)) {
24
            foreach ($headers as $headerName => $headerValues) {
25
                $httpRequest = $httpRequest
26
                    ->withAddedHeader($headerName, $headerValues)
27
                ;
28
            }
29
        }
30 1
        return parent::send($httpRequest, $options);
31
    }
32
33
    /**
34
     * @param ClientRequestInterface $request
35
     * @param array|null $headers
36
     * @param array $options
37
     * @return PromiseInterface
38
     */
39 1
    public function executeAsync(ClientRequestInterface $request, array $headers = null, array $options = [])
40
    {
41 1
        $httpRequest = $request->httpRequest();
42 1
        if (is_array($headers)) {
43
            foreach ($headers as $headerName => $headerValues) {
44
                $httpRequest = $httpRequest
45
                    ->withAddedHeader($headerName, $headerValues)
46
                ;
47
            }
48
        }
49 1
        return parent::sendAsync($httpRequest, $options);
50
    }
51
}
52