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.
Completed
Pull Request — master (#43)
by Martin
06:34
created

AbstractHttpProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getClient() 0 4 1
A getResponse() 0 15 3
1
<?php
2
namespace UserAgentParser\Provider\Http;
3
4
use GuzzleHttp\Client;
5
use GuzzleHttp\Exception\RequestException as GuzzleHttpException;
6
use GuzzleHttp\Psr7\Response;
7
use Psr\Http\Message\RequestInterface;
8
use UserAgentParser\Exception;
9
use UserAgentParser\Provider\AbstractProvider;
10
11
abstract class AbstractHttpProvider extends AbstractProvider
12
{
13
    /**
14
     *
15
     * @var Client
16
     */
17
    private $client;
18
19
    /**
20
     *
21
     * @param Client $client
22
     */
23 3
    public function __construct(Client $client)
24
    {
25 3
        $this->client = $client;
26 3
    }
27
28
    /**
29
     *
30
     * @return Client
31
     */
32 3
    public function getClient()
33
    {
34 3
        return $this->client;
35
    }
36
37
    /**
38
     *
39
     * @param  RequestInterface           $request
40
     * @return Response
41
     * @throws Exception\RequestException
42
     */
43 3
    protected function getResponse(RequestInterface $request)
44
    {
45
        try {
46
            /* @var $response \GuzzleHttp\Psr7\Response */
47 3
            $response = $this->getClient()->send($request);
48 3
        } catch (GuzzleHttpException $ex) {
49 1
            throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '"', null, $ex);
50
        }
51
52 2
        if ($response->getStatusCode() !== 200) {
53 1
            throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Status code is: "' . $response->getStatusCode() . '"');
54
        }
55
56 1
        return $response;
57
    }
58
}
59