Passed
Pull Request — master (#222)
by Dmitriy
12:29
created

StaticRuleHandlerResolver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
use Yiisoft\Validator\Exception\RuleHandlerNotFoundException;
8
use Yiisoft\Validator\Rule\RuleHandlerInterface;
9
10
final class StaticRuleHandlerResolver implements RuleHandlerResolverInterface
11
{
12
    private array $validators;
13
14 513
    public function __construct(array $validators)
15
    {
16 513
        $this->validators = $validators;
17
    }
18
19 28
    public function resolve(RuleInterface $rule): RuleHandlerInterface
20
    {
21 28
        return $this->validators[$rule->getHandlerClassName()] ?? throw new RuleHandlerNotFoundException($rule);
22
    }
23
}
24