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

ContainerRuleHandlerResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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