Passed
Branch master (aa5120)
by Yo
02:31
created

ContainerMethodResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
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 ContainerMethodResolver
12
 */
13
class ContainerMethodResolver implements MethodResolverInterface
14
{
15
    /** @var ContainerInterface */
16
    private $container;
17
    /** @var ServiceNameResolverInterface */
18
    private $serviceNameResolver;
19
20 2
    public function __construct(
21
        ContainerInterface $container,
22
        ServiceNameResolverInterface $serviceNameResolver
23
    ) {
24 2
        $this->container = $container;
25 2
        $this->serviceNameResolver = $serviceNameResolver;
26 2
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 2
    public function resolve(string $methodName) : JsonRpcMethodInterface
32
    {
33 2
        $serviceName = $this->serviceNameResolver->resolve($methodName);
34 2
        if (!$this->container->has($serviceName)) {
35 1
            throw new JsonRpcMethodNotFoundException($methodName);
36
        }
37
38 1
        return $this->container->get($serviceName);
39
    }
40
}
41