HttpClientWrapper   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 52
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getWrappedClient() 0 4 1
A send() 0 6 2
A request() 0 6 1
A wrapResponse() 0 11 3
1
<?php
2
3
4
namespace Mrzard\OpenExchangeRates\Service;
5
6
7
class HttpClientWrapper implements HttpClientInterface
8
{
9
    /**
10
     * @var object
11
     */
12
    private $wrappedClient;
13
14
    public function __construct($client)
15
    {
16
        $this->wrappedClient = $client;
17
    }
18
19
    /**
20
     * @return object
21
     */
22
    public function getWrappedClient()
23
    {
24
        return $this->wrappedClient;
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function send($request)
31
    {
32
        $request = $request instanceof HttpRequestInterface ? $request->request() : new HttpRequestWrapper($request);
33
34
        return $this->wrapResponse($this->wrappedClient->send($request));
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function request($method, $uri = null, array $options = [])
41
    {
42
        $response = $this->wrappedClient->request($method, $uri, $options);
43
44
        return $this->wrapResponse($response);
45
    }
46
47
    private function wrapResponse($response)
48
    {
49
        if ($response instanceof HttpResponseInterface) {
50
            return $response;
51
        }
52
        if (!method_exists($response, 'getBody')) {
53
54
            throw new \ErrorException('Supplied client\'s response don\'t have method `getBody()`');
55
        }
56
        return new HttpResponseWrapper($response);
57
    }
58
}
59
60