Completed
Push — master ( 50831e...b2bfbe )
by Márk
01:58
created

Client   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 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
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\Guzzle6;
4
5
use GuzzleHttp\Client as GuzzleClient;
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\Common\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 Client 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(\GuzzleHttp\choose_handler());
35
            $handlerStack->push(Middleware::prepareBody(), 'prepare_body');
36
            $client = new GuzzleClient(['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 Promise($promise, $request);
49
    }
50
}
51