1 | <?php |
||
25 | class RateLimitHandler |
||
26 | { |
||
27 | /** |
||
28 | * @var CacheItemPoolInterface |
||
29 | */ |
||
30 | private $cacheItemPool; |
||
31 | |||
32 | /** |
||
33 | * @var TokenStorageInterface |
||
34 | */ |
||
35 | private $tokenStorage; |
||
36 | |||
37 | /** |
||
38 | * @var AuthorizationCheckerInterface |
||
39 | */ |
||
40 | private $authorizationChecker; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | private $throttleConfig; |
||
46 | |||
47 | /** |
||
48 | * @var int |
||
49 | */ |
||
50 | private $limit; |
||
51 | |||
52 | /** |
||
53 | * @var int |
||
54 | */ |
||
55 | private $remaining; |
||
56 | |||
57 | /** |
||
58 | * @var int |
||
59 | */ |
||
60 | private $reset; |
||
61 | |||
62 | /** |
||
63 | * @var |
||
64 | */ |
||
65 | private $enabled = true; |
||
66 | |||
67 | /** |
||
68 | * @var bool |
||
69 | */ |
||
70 | private $rateLimitExceeded = false; |
||
71 | |||
72 | /** |
||
73 | * RateLimitHandler constructor. |
||
74 | * |
||
75 | * @param CacheItemPoolInterface $cacheItemPool |
||
76 | * @param TokenStorageInterface $tokenStorage |
||
77 | * @param AuthorizationCheckerInterface $authorizationChecker |
||
78 | * @param array $throttleConfig |
||
79 | */ |
||
80 | 8 | public function __construct( |
|
91 | |||
92 | /** |
||
93 | * @return bool |
||
94 | */ |
||
95 | 8 | public function isEnabled() |
|
99 | |||
100 | /** |
||
101 | * @return bool |
||
102 | */ |
||
103 | 5 | public function isRateLimitExceeded() |
|
107 | |||
108 | /** |
||
109 | * @return array |
||
110 | */ |
||
111 | 7 | public function getRateLimitInfo(): array |
|
119 | |||
120 | /** |
||
121 | * @param string $ip |
||
122 | * @param string|null $username |
||
123 | * @param string|null $userRole |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | 8 | public static function generateCacheKey(string $ip, string $username = null, string $userRole = null): string |
|
135 | |||
136 | /** |
||
137 | * @param Request $request |
||
138 | * |
||
139 | * @throws \Doctrine\Common\Annotations\AnnotationException |
||
140 | * @throws \Psr\Cache\InvalidArgumentException |
||
141 | * @throws \ReflectionException |
||
142 | */ |
||
143 | 8 | public function handle(Request $request) |
|
164 | |||
165 | /** |
||
166 | * @param string $key |
||
167 | * @param int $limit |
||
168 | * @param int $period |
||
169 | * |
||
170 | * @throws \Psr\Cache\InvalidArgumentException |
||
171 | */ |
||
172 | 7 | protected function decreaseRateLimitRemaining(string $key, int $limit, int $period) |
|
215 | |||
216 | /** |
||
217 | * @param Request $request |
||
218 | * |
||
219 | * @return array |
||
220 | */ |
||
221 | 8 | private function getThrottle(Request $request, ApiRateLimit $annotation) |
|
254 | } |
||
255 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.