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
Push — master ( f9e8ce...6c7c28 )
by Jorge
01:54
created

AnalyticsResponse::getDebugResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace TheIconic\Tracking\GoogleAnalytics;
4
5
use Psr\Http\Message\RequestInterface;
6
use Psr\Http\Message\ResponseInterface;
7
use GuzzleHttp\Promise\PromiseInterface;
8
9
/**
10
 * Class AnalyticsResponse
11
 *
12
 * Represents the response got from GA.
13
 *
14
 * @package TheIconic\Tracking\GoogleAnalytics
15
 */
16
class AnalyticsResponse
17
{
18
    /**
19
     * HTTP status code for the response.
20
     *
21
     * @var null|int
22
     */
23
    protected $httpStatusCode;
24
25
    /**
26
     * Request URI that was used to send the hit.
27
     *
28
     * @var string
29
     */
30
    protected $requestUrl;
31
32
    /**
33
     * Response body.
34
     *
35
     * @var string
36
     */
37
    protected $responseBody;
38
39
    /**
40
     * Gets the relevant data from the Guzzle clients.
41
     *
42
     * @param RequestInterface $request
43
     * @param ResponseInterface|PromiseInterface $response
44
     */
45
    public function __construct(RequestInterface $request, $response)
46
    {
47
        if ($response instanceof ResponseInterface) {
48
            $this->httpStatusCode = $response->getStatusCode();
49
            $this->responseBody = $response->getBody()->getContents();
50
        } elseif ($response instanceof PromiseInterface) {
51
            $this->httpStatusCode = null;
52
            $this->responseBody = null;
53
        } else {
54
            throw new \InvalidArgumentException(
55
                'Second constructor argument "response" must be instance of ResponseInterface or PromiseInterface'
56
            );
57
        }
58
59
        $this->requestUrl = (string) $request->getUri();
60
    }
61
62
    /**
63
     * Gets the HTTP status code.
64
     * It return NULL if the request was asynchronous since we are not waiting for the response.
65
     *
66
     * @return null|int
67
     */
68
    public function getHttpStatusCode()
69
    {
70
        return $this->httpStatusCode;
71
    }
72
73
    /**
74
     * Gets the request URI used to get the response.
75
     *
76
     * @return string
77
     */
78
    public function getRequestUrl()
79
    {
80
        return $this->requestUrl;
81
    }
82
83
    /**
84
     * Gets the debug response. Returns empty array if no response found.
85
     *
86
     * @return array
87
     */
88
    public function getDebugResponse()
89
    {
90
        $debugResponse = [];
91
92
        if (!empty($this->responseBody)) {
93
            $debugResponse = json_decode($this->responseBody, true);
94
        }
95
96
        return $debugResponse;
97
    }
98
}
99