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

FirstMatchedRateLimitProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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