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 — develop ( 853650...6daea0 )
by Gavin
06:42 queued 04:09
created

MultiformatResponse::getData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace JumpCloud\Response;
4
5
use GuzzleHttp\Psr7\Response as HttpResponse;
6
use Webmozart\Json\JsonDecoder;
7
8
class MultiformatResponse implements ResponseInterface
9
{
10
    use ResponseTrait;
11
12
    /**
13
     * @var
14
     */
15
    private $data;
16
17
    /**
18
     * @var int
19
     */
20
    private $total;
21
22
    /**
23
     * @var JsonDecoder
24
     */
25
    private $jsonDecoder;
26
27
    /**
28
     * Response constructor.
29
     * @param HttpResponse $response
30
     */
31
    public function __construct(HttpResponse $response)
32
    {
33
        $this->response = $response;
34
        $this->data = false;
35
        $this->jsonDecoder = new JsonDecoder();
36
    }
37
38
    public function getData()
39
    {
40
        if ($this->data === false) {
41
            $this->handleResponse();
42
        }
43
44
        return $this->data;
45
    }
46
47
    public function getTotal()
48
    {
49
        if ($this->total === null) {
50
            $this->handleResponse();
51
        }
52
53
        return $this->total;
54
    }
55
56
    /**
57
     * @throws \Webmozart\Json\ValidationFailedException
58
     */
59
    private function handleResponse()
60
    {
61
        if ($this->getBody()->getSize() > 0) {
62
            $body = (string)$this->getBody();
63
            $data = $this->jsonDecoder->decode($body);
64
65
            if (isset($data->results, $data->totalCount)) {
66
                $this->total = $data->totalCount;
67
                $this->data = $data->results;
68
                
69
                return;
70
            }
71
        }
72
73
        $this->data = null;
74
        $this->total = 0;
75
    }
76
}
77