QuotaExceeded::resetsAt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Zenstruck\Governator\Exception;
4
5
use Zenstruck\Governator\Quota;
6
7
/**
8
 * @author Kevin Bond <[email protected]>
9
 */
10
final class QuotaExceeded extends \RuntimeException
11
{
12
    private Quota $quota;
13
14 40
    public function __construct(Quota $quota)
15
    {
16 40
        $this->quota = $quota;
17
18 40
        parent::__construct(\sprintf('Quota Exceeded (%d/%d), resets in %d seconds.', $quota->hits(), $quota->limit(), $quota->resetsIn()));
19 40
    }
20
21
    /**
22
     * @return Quota The exceeded Quota object for the throttle
23
     */
24 9
    public function quota(): Quota
25
    {
26 9
        return $this->quota;
27
    }
28
29
    /**
30
     * @return string The throttle's unique identifier
31
     */
32 9
    public function resource(): string
33
    {
34 9
        return $this->quota->resource();
35
    }
36
37
    /**
38
     * @return int The throttle's limit
39
     */
40 9
    public function limit(): int
41
    {
42 9
        return $this->quota->limit();
43
    }
44
45
    /**
46
     * @return int The number of throttle hits
47
     */
48 20
    public function hits(): int
49
    {
50 20
        return $this->quota->hits();
51
    }
52
53
    /**
54
     * @return int Number of allowed hits before the throttle resets (always 0)
55
     */
56 18
    public function remaining(): int
57
    {
58 18
        return 0;
59
    }
60
61
    /**
62
     * @return \DateTimeImmutable When the throttle resets (never in the past)
63
     */
64 9
    public function resetsAt(): \DateTimeImmutable
65
    {
66 9
        return $this->quota->resetsAt();
67
    }
68
69
    /**
70
     * @return int Number of seconds until the throttle resets (never negative)
71
     */
72 38
    public function resetsIn(): int
73
    {
74 38
        return $this->quota->resetsIn();
75
    }
76
}
77