1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Symfony package. |
||
5 | * |
||
6 | * (c) Fabien Potencier <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Biurad\Security\RateLimiter; |
||
13 | |||
14 | use Psr\Http\Message\ServerRequestInterface; |
||
15 | use Symfony\Component\RateLimiter\LimiterInterface; |
||
0 ignored issues
–
show
|
|||
16 | use Symfony\Component\RateLimiter\Policy\NoLimiter; |
||
0 ignored issues
–
show
The type
Symfony\Component\RateLimiter\Policy\NoLimiter was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
17 | use Symfony\Component\RateLimiter\RateLimit; |
||
0 ignored issues
–
show
The type
Symfony\Component\RateLimiter\RateLimit was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
18 | |||
19 | /** |
||
20 | * An implementation of RequestRateLimiterInterface that fits most use-cases. |
||
21 | * |
||
22 | * @author Wouter de Jong <[email protected]> |
||
23 | * @author Divine Niiquaye Ibok <[email protected]> |
||
24 | */ |
||
25 | abstract class AbstractRequestRateLimiter |
||
26 | { |
||
27 | public function consume(ServerRequestInterface $request): RateLimit |
||
28 | { |
||
29 | $limiters = $this->getLimiters($request); |
||
30 | if (0 === \count($limiters)) { |
||
31 | $limiters = [new NoLimiter()]; |
||
32 | } |
||
33 | |||
34 | $minimalRateLimit = null; |
||
35 | foreach ($limiters as $limiter) { |
||
36 | $rateLimit = $limiter->consume(1); |
||
37 | |||
38 | if (null === $minimalRateLimit || $rateLimit->getRemainingTokens() < $minimalRateLimit->getRemainingTokens()) { |
||
39 | $minimalRateLimit = $rateLimit; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | return $minimalRateLimit; |
||
44 | } |
||
45 | |||
46 | public function reset(ServerRequestInterface $request): void |
||
47 | { |
||
48 | foreach ($this->getLimiters($request) as $limiter) { |
||
49 | $limiter->reset(); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @return array<int,LimiterInterface> a set of limiters using keys extracted from the request |
||
55 | */ |
||
56 | abstract protected function getLimiters(ServerRequestInterface $request): array; |
||
57 | } |
||
58 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths