ThrottleConfiguration::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
1
<?php
2
3
namespace BenTools\GuzzleHttp\Middleware;
4
5
use BenTools\Psr7\RequestMatcherInterface;
6
use Psr\Http\Message\RequestInterface;
7
8
class ThrottleConfiguration implements RequestMatcherInterface
9
{
10
    /**
11
     * @var RequestMatcherInterface
12
     */
13
    private $requestMatcher;
14
15
    /**
16
     * @var int
17
     */
18
    private $maxRequests;
19
20
    /**
21
     * @var float
22
     */
23
    private $duration;
24
25
    /**
26
     * @var string
27
     */
28
    private $storageKey;
29
30
    /**
31
     * ThrottleConfiguration constructor.
32
     * @param RequestMatcherInterface $requestMatcher
33
     * @param int                     $maxRequests
34
     * @param float                     $duration
35
     * @param string                  $storageKey
36
     */
37
    public function __construct(RequestMatcherInterface $requestMatcher, int $maxRequests, float $duration, string $storageKey)
38
    {
39
        $this->requestMatcher = $requestMatcher;
40
        $this->maxRequests = $maxRequests;
41
        $this->duration = $duration;
42
        $this->storageKey = $storageKey;
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function matchRequest(RequestInterface $request)
49
    {
50
        return $this->requestMatcher->matchRequest($request);
51
    }
52
53
    /**
54
     * @return int
55
     */
56
    public function getMaxRequests(): int
57
    {
58
        return $this->maxRequests;
59
    }
60
61
    /**
62
     * @return float
63
     */
64
    public function getDuration(): float
65
    {
66
        return $this->duration;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getStorageKey(): string
73
    {
74
        return $this->storageKey;
75
    }
76
}
77