1 | <?php |
||
25 | final class RequestsPerWindowRateLimiter implements RateLimiterInterface |
||
26 | { |
||
27 | const LIMIT_EXCEEDED_HTTP_STATUS_CODE = 429; //HTTP 429 "Too Many Requests" (RFC 6585) |
||
28 | |||
29 | const HEADER_LIMIT = 'X-RateLimit-Limit'; |
||
30 | const HEADER_REMAINING = 'X-RateLimit-Remaining'; |
||
31 | const HEADER_RESET = 'X-RateLimit-Reset'; |
||
32 | |||
33 | /** |
||
34 | * @var StorageInterface |
||
35 | */ |
||
36 | private $storage; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private $options; |
||
42 | |||
43 | /** |
||
44 | * @var IdentityGeneratorInterface |
||
45 | */ |
||
46 | private $identityGenerator; |
||
47 | |||
48 | /** |
||
49 | * @var array |
||
50 | */ |
||
51 | private $rateLimit; |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | private static $defaultOptions = [ |
||
57 | 'limit' => 100, |
||
58 | 'window' => 900, //15 minutes |
||
59 | 'limitExceededHandler' => null, |
||
60 | ]; |
||
61 | |||
62 | 2 | private function __construct(StorageInterface $storage, array $options, IdentityGeneratorInterface $identityGenerator) |
|
68 | |||
69 | 2 | public static function create(StorageInterface $storage, array $options = [], IdentityGeneratorInterface $identityGenerator = null) |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | 2 | public function __invoke(RequestInterface $request, ResponseInterface $response, callable $out = null) |
|
101 | |||
102 | 2 | private function initRateLimit(string $key) |
|
115 | |||
116 | 2 | private function isLimitExceeded() : bool |
|
120 | |||
121 | 2 | private function updateRateLimit() |
|
125 | |||
126 | 2 | private function shouldResetRateLimit() : bool |
|
130 | |||
131 | private function resetRateLimit() |
||
138 | |||
139 | 2 | private function onLimitExceeded(RequestInterface $request, ResponseInterface $response) : ResponseInterface |
|
154 | |||
155 | 2 | private function onBelowLimit(RequestInterface $request, ResponseInterface $response, callable $out = null) : ResponseInterface |
|
161 | |||
162 | 2 | private function setRateLimitHeaders(ResponseInterface $response) : ResponseInterface |
|
170 | } |
||
171 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..