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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 48
c 0
b 0
f 0
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
/**
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