Passed
Push — initial_version ( a4a764...124241 )
by Agaletskiy
01:58
created

FirstMatchedRateLimitProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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
20 4
    public function provide($command): ?RateLimit
21
    {
22 4
        $result = null;
23
24 4
        foreach ($this->rateLimitProviders as $rateLimitProvider) {
25 4
            $result = $rateLimitProvider->provide($command);
26 4
            if ($result !== null) {
27 4
                break;
28
            }
29
        }
30
31 4
        return $result;
32
    }
33
}
34