| Total Complexity | 3 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 17 | class RateLimitToUserApiMiddleware implements MiddlewareInterface |
||
| 18 | { |
||
| 19 | private StorageInterface $storage; |
||
| 20 | |||
| 21 | private const LIMIT = 2; |
||
| 22 | private const PERIOD_IN_SECOND = 5; |
||
| 23 | private const TTR_COUNTER = 10; |
||
| 24 | private const PREFIX_STORAGE = 'user-rate-limit-'; |
||
| 25 | |||
| 26 | public function __construct(StorageInterface $storage) |
||
| 27 | { |
||
| 28 | $this->storage = $storage; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
| 32 | { |
||
| 33 | $responseFactory = new ResponseFactory(); |
||
| 34 | $limitingPolicy = new LimitPerIp(); |
||
| 35 | |||
| 36 | $middleware = new LimitRequestsMiddleware($this->getCounter(), $responseFactory, $limitingPolicy); |
||
| 37 | return $middleware->process($request, $handler); |
||
| 38 | } |
||
| 39 | |||
| 40 | private function getCounter(): Counter |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |