RateLimits::fromHeaders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tequilarapido\Twit;
4
5
class RateLimits
6
{
7
    public $limit;
8
9
    public $remaining;
10
11
    public $reset;
12
13
    /**
14
     * Construct instance from headers response.
15
     *
16
     * @param $headers
17
     * @return static
18
     */
19
    public static function fromHeaders($headers)
20
    {
21
        $rateLimits = new static;
22
        $rateLimits->limit = array_get($headers, 'x_rate_limit_limit');
23
        $rateLimits->remaining = array_get($headers, 'x_rate_limit_remaining');
24
        $rateLimits->reset = array_get($headers, 'x_rate_limit_reset');
25
26
        return $rateLimits;
27
    }
28
29
    /**
30
     * @return int seconds before rate limit reset.
31
     */
32
    public function waitTime()
33
    {
34
        return (int) $this->reset - time() + 5; /* we add 5 secs for safety !*/
35
    }
36
}
37