Passed
Pull Request — master (#222)
by Dmitriy
02:25
created

ContainerRuleHandlerResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
declare(strict_types=1);
3
4
namespace Yiisoft\Validator;
5
6
use Psr\Container\ContainerInterface;
7
use Throwable;
8
use Yiisoft\Validator\Exception\RuleHandlerNotFoundException;
9
use Yiisoft\Validator\Rule\RuleHandlerInterface;
10
11
final class ContainerRuleHandlerResolver implements RuleHandlerResolverInterface
12
{
13
    private ContainerInterface $container;
14
15
    public function __construct(ContainerInterface $container)
16
    {
17
        $this->container = $container;
18
    }
19
20
    public function resolve(RuleInterface $rule): RuleHandlerInterface
21
    {
22
        try {
23
            return $this->container->get($rule->getHandlerClassName());
24
        } catch (Throwable $e) {
25
            throw new RuleHandlerNotFoundException($rule, $e);
26
        }
27
    }
28
}
29