LimitedApiRate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 57
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A getLimit() 0 4 1
A canMakeAnotherCall() 0 5 2
A nextWindow() 0 4 1
1
<?php
2
3
namespace Twitter\API\REST\Response;
4
5
class LimitedApiRate implements ApiRate
6
{
7
    /** @var int */
8
    private $limit;
9
10
    /** @var int */
11
    private $remaining;
12
13
    /** @var \DateTimeInterface */
14
    private $reset;
15
16
    /**
17
     * LimitedApiRate constructor.
18
     *
19
     * @param int $limit
20
     * @param int $remaining
21
     * @param int $reset
22
     */
23 15
    public function __construct(
24
        $limit,
25
        $remaining,
26
        $reset
27
    ) {
28 15
        $this->limit = $limit;
29 15
        $this->remaining = $remaining;
30 15
        $this->reset = \DateTimeImmutable::createFromFormat(
31 15
            'U',
32 15
            $reset,
33 15
            new \DateTimeZone('UTC')
34 10
        );
35 15
    }
36
37
    /**
38
     * @return int
39
     */
40 6
    public function getLimit()
41
    {
42 6
        return $this->limit;
43
    }
44
45
    /**
46
     * @return bool
47
     */
48 9
    public function canMakeAnotherCall()
49
    {
50 9
        return $this->reset <= new \DateTimeImmutable('now', new \DateTimeZone('UTC'))
51 9
            || $this->remaining > 0;
52
    }
53
54
    /**
55
     * @return \DateTimeInterface
56
     */
57 9
    public function nextWindow()
58
    {
59 9
        return $this->reset;
60
    }
61
}
62