Passed
Push — master ( f9d022...66a5c5 )
by Sergei
02:37
created

RuleHandlerContainer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 19
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 13 3
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\RuleHandlerResolver;
6
7
use Psr\Container\ContainerInterface;
8
use Psr\Container\NotFoundExceptionInterface;
9
use Yiisoft\Validator\Exception\RuleHandlerInterfaceNotImplementedException;
10
use Yiisoft\Validator\Exception\RuleHandlerNotFoundException;
11
use Yiisoft\Validator\RuleHandlerInterface;
12
use Yiisoft\Validator\RuleHandlerResolverInterface;
13
14
final class RuleHandlerContainer implements RuleHandlerResolverInterface
15
{
16
    public function __construct(private ContainerInterface $container)
17
    {
18
    }
19
20
    public function resolve(string $className): RuleHandlerInterface
21
    {
22
        try {
23
            $ruleHandler = $this->container->get($className);
24
        } catch (NotFoundExceptionInterface $e) {
25
            throw new RuleHandlerNotFoundException($className, $e);
26
        }
27
28
        if (!$ruleHandler instanceof RuleHandlerInterface) {
29
            throw new RuleHandlerInterfaceNotImplementedException($className);
30
        }
31
32
        return $ruleHandler;
33
    }
34
}
35