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

MatchingCommandClassRateLimitProvider::provide()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
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 MatchingCommandClassRateLimitProvider implements RateLimitProviderInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $className;
13
    /**
14
     * @var int
15
     */
16
    private $limit;
17
    /**
18
     * @var int
19
     */
20
    private $milliseconds;
21
22 3
    public function __construct(string $className, int $limit, int $milliseconds)
23
    {
24 3
        $this->className = $className;
25 3
        $this->limit = $limit;
26 3
        $this->milliseconds = $milliseconds;
27 3
    }
28
29
30 3
    public function provide($command): ?RateLimit
31
    {
32 3
        if (!$command instanceof $this->className) {
33 1
            return null;
34
        }
35
36 2
        return new RateLimit($this->className, $this->limit, $this->milliseconds);
37
    }
38
}
39