Completed
Push — master ( b65b29...f39982 )
by Tobias
03:16 queued 01:01
created

RequestManager::sendRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 10
rs 9.4286
cc 2
eloc 6
nc 2
nop 5
1
<?php
2
3
namespace Happyr\LinkedIn\Http;
4
5
use Happyr\LinkedIn\Exception\LinkedInTransferException;
6
use Http\Client\Exception\TransferException;
7
use Http\Client\HttpClient;
8
use Http\Discovery\HttpClientDiscovery;
9
use Http\Discovery\MessageFactoryDiscovery;
10
11
class RequestManager implements RequestManagerInterface
12
{
13
    /**
14
     * @var \Http\Client\HttpClient
15
     */
16
    private $httpClient;
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function sendRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
22
    {
23
        $request = MessageFactoryDiscovery::find()->createRequest($method, $uri, $headers, $body, $protocolVersion);
24
25
        try {
26
            return $this->getHttpClient()->sendRequest($request);
27
        } catch (TransferException $e) {
28
            throw new LinkedInTransferException('Error while requesting data from LinkedIn.com: '.$e->getMessage(), $e->getCode(), $e);
29
        }
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function setHttpClient(HttpClient $httpClient)
36
    {
37
        $this->httpClient = $httpClient;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @return HttpClient
44
     */
45
    protected function getHttpClient()
46
    {
47
        if ($this->httpClient === null) {
48
            $this->httpClient = HttpClientDiscovery::find();
49
        }
50
51
        return $this->httpClient;
52
    }
53
}
54