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
Pull Request — master (#26)
by
unknown
05:57
created

RateLimitException::getHeaderValue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 2
crap 3.072
1
<?php namespace Vindi\Exceptions;
2
3
use Exception;
4
5
class RateLimitException extends Exception
6
{
7
    /**
8
     * @var int
9
     */
10
    protected $limit;
11
12
    /**
13
     * @var int
14
     */
15
    protected $reset;
16
17
    /**
18
     * @var int
19
     */
20
    protected $remaining;
21
22
    /**
23
     * @var int
24
     */
25
    protected $retryAfter;
26
27
    /**
28
     * RateLimitException constructor.
29
     *
30
     * @param mixed $response API response.
31
     */
32 2
    public function __construct($response)
33
    {
34 2
        $this->limit = $this->getHeaderValue($response, 'Rate-Limit-Limit');
35 2
        $this->reset = $this->getHeaderValue($response, 'Rate-Limit-Reset');
36 2
        $this->remaining = $this->getHeaderValue($response, 'Rate-Limit-Remaining');
37 2
        $this->retryAfter = $this->getHeaderValue($response, 'Retry-After');
38
39 2
        $this->message = "O limite de {$this->limit} requisições por minuto para a API foi atingido.";
40 2
    }
41
42
    /**
43
     * Get first array value from specified header as integer.
44
     *
45
     * @param mixed  $response API response.
46
     * @param string $name     Header name.
47
     *
48
     * @returns int
49
     */
50 2
    private function getHeaderValue($response, $name)
51
    {
52 2
        $header = $response->getHeader($name);
53
54 2
        if (! $header || ! count($header)) {
55
            return 0;
56
        }
57
58 2
        return (int) array_shift($header);
59
    }
60
61
    /**
62
     * Maximum request number per minute.
63
     *
64
     * @return int
65
     */
66 2
    public function getLimit()
67
    {
68 2
        return $this->limit;
69
    }
70
71
    /**
72
     * Timestamp until there are new remaining requests.
73
     *
74
     * @return int
75
     */
76 2
    public function getReset()
77
    {
78 2
        return $this->reset;
79
    }
80
81
    /**
82
     * Remaining requests.
83
     *
84
     * @return int
85
     */
86 2
    public function getRemaining()
87
    {
88 2
        return $this->remaining;
89
    }
90
91
    /**
92
     * When it's possible to make the next request.
93
     *
94
     * @return int
95
     */
96 2
    public function getRetryAfter()
97
    {
98 2
        return $this->retryAfter;
99
    }
100
}
101