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

HttpClient::executeAsync()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
ccs 4
cts 6
cp 0.6667
rs 10
cc 3
nc 2
nop 3
crap 3.3332
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