Completed
Pull Request — master (#1)
by Agaletskiy
04:38 queued 01:44
created

FirstMatchedRateLimitProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A provide() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\Tactician\RateLimit\RateLimiter;
6
7
final class FirstMatchedRateLimitProvider implements RateLimitProviderInterface
8
{
9
    /**
10
     * @var RateLimitProviderInterface[]
11
     */
12
    private $rateLimitProviders;
13
14 4
    public function __construct(RateLimitProviderInterface ...$rateLimitProviders)
15
    {
16 4
        $this->rateLimitProviders = $rateLimitProviders;
17 4
    }
18
19 4
    public function provide($command): ?RateLimit
20
    {
21 4
        $result = null;
22
23 4
        foreach ($this->rateLimitProviders as $rateLimitProvider) {
24 4
            $result = $rateLimitProvider->provide($command);
25 4
            if (null !== $result) {
26 4
                break;
27
            }
28
        }
29
30 4
        return $result;
31
    }
32
}
33