Completed
Push — master ( 5e3462...974d4d )
by Nikola
04:09
created

Rate::custom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RateLimit;
6
7
use Assert\Assertion;
8
9
class Rate
10
{
11
    /** @var int */
12
    protected $operations;
13
14
    /** @var int */
15
    protected $interval;
16
17 10
    final protected function __construct(int $operations, int $interval)
18
    {
19 10
        Assertion::greaterThan($operations, 0, 'Quota must be greater than zero');
20 10
        Assertion::greaterThan($interval, 0, 'Seconds interval must be greater than zero');
21
22 10
        $this->operations = $operations;
23 10
        $this->interval = $interval;
24 10
    }
25
26 3
    public static function perSecond(int $operations)
27
    {
28 3
        return new static($operations, 1);
29
    }
30
31 2
    public static function perMinute(int $operations)
32
    {
33 2
        return new static($operations, 60);
34
    }
35
36 3
    public static function perHour(int $operations)
37
    {
38 3
        return new static($operations, 3600);
39
    }
40
41 1
    public static function perDay(int $operations)
42
    {
43 1
        return new static($operations, 86400);
44
    }
45
46 1
    public static function custom(int $operations, int $interval)
47
    {
48 1
        return new static($operations, $interval);
49
    }
50
51 10
    public function getOperations(): int
52
    {
53 10
        return $this->operations;
54
    }
55
56 10
    public function getInterval(): int
57
    {
58 10
        return $this->interval;
59
    }
60
}
61