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

ContainerRuleHandlerResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 7
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 6 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
use Psr\Container\ContainerInterface;
8
use Throwable;
9
use Yiisoft\Validator\Exception\RuleHandlerNotFoundException;
10
use Yiisoft\Validator\Rule\RuleHandlerInterface;
11
12
final class ContainerRuleHandlerResolver implements RuleHandlerResolverInterface
13
{
14
    private ContainerInterface $container;
15
16
    public function __construct(ContainerInterface $container)
17
    {
18
        $this->container = $container;
19
    }
20
21
    public function resolve(RuleInterface $rule): RuleHandlerInterface
22
    {
23
        try {
24
            return $this->container->get($rule->getHandlerClassName());
25
        } catch (Throwable $e) {
26
            throw new RuleHandlerNotFoundException($rule, $e);
27
        }
28
    }
29
}
30