Total Complexity | 4 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | final class ThrottleFactory |
||
9 | { |
||
10 | private Store $store; |
||
11 | private string $prefix; |
||
12 | |||
13 | /** |
||
14 | * @param string $prefix Global resource prefix for created throttles |
||
15 | */ |
||
16 | 114 | public function __construct(Store $store, string $prefix = 'throttle_') |
|
17 | { |
||
18 | 114 | $this->store = $store; |
|
19 | 114 | $this->prefix = $prefix; |
|
20 | 114 | } |
|
21 | |||
22 | /** |
||
23 | * Create for passed connection DSN/object. |
||
24 | * |
||
25 | * @param string|object $connection |
||
26 | * @param string $prefix Global resource prefix for created throttles |
||
27 | */ |
||
28 | 7 | public static function for($connection, string $prefix = 'throttle_'): self |
|
29 | { |
||
30 | 7 | return new self(StoreFactory::create($connection), $prefix); |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * Create a throttle. |
||
35 | * |
||
36 | * @param string $resource Unique identifier for the throttle |
||
37 | * @param int $limit The maximum number of throttle "hits" in its "time window" |
||
38 | * @param int $ttl the "time window" for the throttle in seconds |
||
39 | */ |
||
40 | 111 | public function create(string $resource, int $limit, int $ttl): Throttle |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Create a fluent interface throttle builder. |
||
47 | * |
||
48 | * @see ThrottleBuilder |
||
49 | * |
||
50 | * @param string ...$resource Unique identifier(s) for the throttle |
||
51 | */ |
||
52 | 41 | public function throttle(string ...$resource): ThrottleBuilder |
|
57 |