RequestManager   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 72
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A sendRequest() 0 10 2
A setHttpClient() 0 6 1
A getHttpClient() 0 8 2
A setMessageFactory() 0 6 1
A getMessageFactory() 0 8 2
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
use Http\Message\MessageFactory;
11
12
/**
13
 * A class to create HTTP requests and to send them.
14
 *
15
 * @author Tobias Nyholm <[email protected]>
16
 */
17
class RequestManager implements RequestManagerInterface
18
{
19
    /**
20
     * @var \Http\Client\HttpClient
21
     */
22
    private $httpClient;
23
24
    /**
25
     * @var \Http\Message\MessageFactory
26
     */
27
    private $messageFactory;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function sendRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
33
    {
34
        $request = $this->getMessageFactory()->createRequest($method, $uri, $headers, $body, $protocolVersion);
35
36
        try {
37
            return $this->getHttpClient()->sendRequest($request);
38
        } catch (TransferException $e) {
39
            throw new LinkedInTransferException('Error while requesting data from LinkedIn.com: '.$e->getMessage(), $e->getCode(), $e);
40
        }
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function setHttpClient(HttpClient $httpClient)
47
    {
48
        $this->httpClient = $httpClient;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @return HttpClient
55
     */
56
    protected function getHttpClient()
57
    {
58
        if ($this->httpClient === null) {
59
            $this->httpClient = HttpClientDiscovery::find();
60
        }
61
62
        return $this->httpClient;
63
    }
64
65
    /**
66
     * @param MessageFactory $messageFactory
67
     *
68
     * @return RequestManager
69
     */
70
    public function setMessageFactory(MessageFactory $messageFactory)
71
    {
72
        $this->messageFactory = $messageFactory;
73
74
        return $this;
75
    }
76
77
    /**
78
     * @return \Http\Message\MessageFactory
79
     */
80
    private function getMessageFactory()
81
    {
82
        if ($this->messageFactory === null) {
83
            $this->messageFactory = MessageFactoryDiscovery::find();
84
        }
85
86
        return $this->messageFactory;
87
    }
88
}
89