Completed
Pull Request — master (#73)
by Tobias
02:16
created

RequestManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sendRequest() 0 6 1
A setHttpClient() 0 6 1
A getHttpClient() 0 8 2
1
<?php
2
3
namespace Happyr\LinkedIn\Http;
4
5
use Http\Client\HttpClient;
6
use Http\Discovery\HttpClientDiscovery;
7
use Http\Discovery\MessageFactoryDiscovery;
8
9
/**
10
 * A request manager builds a request.
11
 *
12
 * @author Tobias Nyholm <[email protected]>
13
 */
14
class RequestManager
15
{
16
    /**
17
     * @var \Http\Client\HttpClient
18
     */
19
    private $httpClient;
20
21
    /**
22
     * @param string $method
23
     * @param string $uri
24
     * @param array  $headers
25
     * @param null   $body
26
     *
27
     * @return \Psr\Http\Message\ResponseInterface
28
     */
29
    public function sendRequest($method, $uri, array $headers = [], $body = null)
30
    {
31
        $request = MessageFactoryDiscovery::find()->createRequest($method, $uri, $headers, $body);
32
33
        return $this->getHttpClient()->sendRequest($request);
34
    }
35
36
    /**
37
     * @param \Http\Client\HttpClient $httpClient
38
     *
39
     * @return RequestManager
40
     */
41
    public function setHttpClient(HttpClient $httpClient)
42
    {
43
        $this->httpClient = $httpClient;
44
45
        return $this;
46
    }
47
48
    /**
49
     * @return HttpClient
50
     */
51
    protected function getHttpClient()
52
    {
53
        if ($this->httpClient === null) {
54
            $this->httpClient = HttpClientDiscovery::find();
55
        }
56
57
        return $this->httpClient;
58
    }
59
}
60