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 ( c48221...42da40 )
by Gavin
07:00 queued 01:58
created

MultiformatResponse::handleResponse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 8.2077

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
ccs 2
cts 12
cp 0.1666
rs 9.4285
cc 3
eloc 10
nc 3
nop 0
crap 8.2077
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 1
    public function __construct(HttpResponse $response)
32
    {
33 1
        $this->response = $response;
34 1
        $this->data = false;
35 1
        $this->jsonDecoder = new JsonDecoder();
36 1
    }
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 1
    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 1
        $this->data = null;
74
        $this->total = 0;
75
    }
76
}
77