Completed
Push — master ( b9d402...9f5801 )
by Joel
04:27
created

Guzzle6HttpAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 63.64%

Importance

Changes 14
Bugs 1 Features 4
Metric Value
wmc 3
c 14
b 1
f 4
lcom 1
cbo 6
dl 0
loc 32
ccs 7
cts 11
cp 0.6364
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A sendAsyncRequest() 0 6 1
1
<?php
2
3
namespace Http\Adapter;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\ClientInterface;
7
use GuzzleHttp\HandlerStack;
8
use GuzzleHttp\Middleware;
9
use Http\Client\HttpAsyncClient;
10
use Http\Client\HttpClient;
11
use Http\Client\Tools\HttpClientEmulator;
12
use Psr\Http\Message\RequestInterface;
13
14
/**
15
 * HTTP Adapter for Guzzle 6.
16
 *
17
 * @author David de Boer <[email protected]>
18
 */
19
class Guzzle6HttpAdapter implements HttpClient, HttpAsyncClient
20
{
21
    use HttpClientEmulator;
22
23
    /**
24
     * @var ClientInterface
25
     */
26
    private $client;
27
28
    /**
29
     * @param ClientInterface|null $client
30
     */
31 324
    public function __construct(ClientInterface $client = null)
32
    {
33 324
        if (!$client) {
34
            $handlerStack = new HandlerStack();
35
            $handlerStack->push(Middleware::prepareBody(), 'prepare_body');
36
            $client = new Client(['handler' => $handlerStack]);
37
        }
38 324
        $this->client = $client;
39 324
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 324
    public function sendAsyncRequest(RequestInterface $request)
45
    {
46 324
        $promise = $this->client->sendAsync($request);
47
48 324
        return new Guzzle6Promise($promise, $request);
49
    }
50
}
51