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.

AbstractHttpProvider::getResponse()   A
last analyzed

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 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 9.4285
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
/**
12
 * Abstraction for all HTTP providers
13
 *
14
 * @author Martin Keckeis <[email protected]>
15
 * @license MIT
16
 */
17
abstract class AbstractHttpProvider extends AbstractProvider
18
{
19
    /**
20
     *
21
     * @var Client
22
     */
23
    private $client;
24
25
    /**
26
     *
27
     * @param Client $client
28
     */
29 3
    public function __construct(Client $client)
30
    {
31 3
        $this->client = $client;
32 3
    }
33
34
    /**
35
     *
36
     * @return Client
37
     */
38 3
    public function getClient()
39
    {
40 3
        return $this->client;
41
    }
42
43
    /**
44
     *
45
     * @param  RequestInterface           $request
46
     * @return Response
47
     * @throws Exception\RequestException
48
     */
49 3
    protected function getResponse(RequestInterface $request)
50
    {
51
        try {
52
            /* @var $response \GuzzleHttp\Psr7\Response */
53 3
            $response = $this->getClient()->send($request);
54 1
        } catch (GuzzleHttpException $ex) {
55 1
            throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '"', null, $ex);
56
        }
57
58 2
        if ($response->getStatusCode() !== 200) {
59 1
            throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Status code is: "' . $response->getStatusCode() . '"');
60
        }
61
62 1
        return $response;
63
    }
64
}
65