Completed
Push — master ( f8807b...5769db )
by Nikola
06:22
created

QuotaPolicy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 42
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A perSecond() 0 4 1
A perMinute() 0 4 1
A perHour() 0 4 1
A getQuota() 0 4 1
A getInterval() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RateLimit;
6
7
use Assert\Assertion;
8
9
class QuotaPolicy
10
{
11
    /** @var int */
12
    protected $quota;
13
14
    /** @var int */
15
    protected $interval;
16
17
    final protected function __construct(int $quota, int $interval)
18
    {
19
        Assertion::greaterThan($quota, 0);
20
        Assertion::greaterThan($interval, 0);
21
22
        $this->quota = $quota;
23
        $this->interval = $interval;
24
    }
25
26
    public static function perSecond(int $quota)
27
    {
28
        return new static($quota, 1);
29
    }
30
31
    public static function perMinute(int $quota)
32
    {
33
        return new static($quota, 60);
34
    }
35
36
    public static function perHour(int $quota)
37
    {
38
        return new static($quota, 3600);
39
    }
40
41
    public function getQuota(): int
42
    {
43
        return $this->quota;
44
    }
45
46
    public function getInterval(): int
47
    {
48
        return $this->interval;
49
    }
50
}
51