RateLimits   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 10
c 1
b 1
f 0
dl 0
loc 30
ccs 0
cts 11
cp 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromHeaders() 0 8 1
A waitTime() 0 3 1
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