GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 603945...58fe0f )
by Harald
03:00 queued 19s
created

Caller   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 7
eloc 15
dl 0
loc 54
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A request() 0 8 2
A getMessageFactory() 0 7 2
A setHttpClient() 0 3 1
A getHttpClient() 0 7 2
1
<?php
2
3
namespace Bokbasen\ApiClient;
4
5
use Bokbasen\ApiClient\Exceptions\BokbasenApiClientException;
6
use Http\Client\HttpClient;
7
use Http\Discovery\HttpClientDiscovery;
8
use Http\Discovery\MessageFactoryDiscovery;
9
use Http\Message\MessageFactory;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Message\StreamInterface;
12
use Psr\Http\Message\UriInterface;
13
14
class Caller
15
{
16
    /**
17
     * @var HttpClient
18
     */
19
    private $httpClient;
20
21
    /**
22
     * @var MessageFactory
23
     */
24
    private $messageFactory;
25
26
    /**
27
     * @param string                               $method
28
     * @param string|UriInterface                  $url
29
     * @param array                                $headers
30
     * @param resource|string|StreamInterface|null $body
31
     *
32
     * @return ResponseInterface
33
     *
34
     * @throws BokbasenApiClientException
35
     */
36 14
    public function request(string $method, $url, array $headers = [], $body = null): ResponseInterface
37
    {
38
        try {
39 14
            return $this->getHttpClient()->sendRequest(
40 14
                $this->getMessageFactory()->createRequest($method, $url, $headers, $body)
41
            );
42 2
        } catch (\Http\Client\Exception | \Exception $e) {
43 2
            throw new BokbasenApiClientException($e->getMessage(), $e->getCode(), $e);
44
        }
45
    }
46
47 14
    protected function getHttpClient(): HttpClient
48
    {
49 14
        if (!$this->httpClient) {
50
            $this->httpClient = HttpClientDiscovery::find();
51
        }
52
53 14
        return $this->httpClient;
54
    }
55
56 14
    protected function getMessageFactory(): MessageFactory
57
    {
58 14
        if (!$this->messageFactory) {
59 14
            $this->messageFactory = MessageFactoryDiscovery::find();
60
        }
61
62 14
        return $this->messageFactory;
63
    }
64
65 16
    public function setHttpClient(HttpClient $httpClient): void
66
    {
67 16
        $this->httpClient = $httpClient;
68 16
    }
69
}
70