Failed Conditions
Pull Request — master (#1)
by Yo
02:13
created

ContainerJsonRpcMethodResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 26
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A resolve() 0 8 2
1
<?php
2
namespace Yoanm\JsonRpcServerPsr11Resolver\Infra\Resolver;
3
4
use Psr\Container\ContainerInterface;
5
use Yoanm\JsonRpcServer\Domain\Exception\JsonRpcMethodNotFoundException;
6
use Yoanm\JsonRpcServer\Domain\Model\JsonRpcMethodInterface;
7
use Yoanm\JsonRpcServer\Domain\Model\MethodResolverInterface;
8
use Yoanm\JsonRpcServerPsr11Resolver\Domain\Model\ServiceNameResolverInterface;
9
10
/**
11
 * Class ContainerJsonRpcMethodResolver
12
 */
13
class ContainerJsonRpcMethodResolver implements MethodResolverInterface
14
{
15
    /** @var ContainerInterface */
16
    private $container;
17
    /** @var ServiceNameResolverInterface */
18
    private $serviceNameResolver;
19
20
    public function __construct(
21
        ContainerInterface $container,
22
        ServiceNameResolverInterface $serviceNameResolver
23
    ) {
24
        $this->container = $container;
25
        $this->serviceNameResolver = $serviceNameResolver;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function resolve(string $methodName) : JsonRpcMethodInterface
32
    {
33
        $serviceName = $this->serviceNameResolver->resolve($methodName);
34
        if (!$this->container->has($serviceName)) {
35
            throw new JsonRpcMethodNotFoundException($methodName);
36
        }
37
38
        return $this->container->get($serviceName);
39
    }
40
}
41