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::getResponse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.4286
cc 3
eloc 8
nc 3
nop 1
crap 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