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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 25.92%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 69
ccs 7
cts 27
cp 0.2592
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getData() 0 8 2
A getTotal() 0 8 2
A handleResponse() 0 17 3
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