Test Failed
Push — feature/init ( ecfce8...b38e47 )
by Yo
05:12
created

DefaultMethodResolver::addMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcServer\Infra\Resolver;
3
4
use Yoanm\JsonRpcServer\Domain\Model\JsonRpcMethodInterface;
5
use Yoanm\JsonRpcServer\Domain\Model\MethodResolverInterface;
6
use Yoanm\JsonRpcServer\Domain\Exception\JsonRpcMethodNotFoundException;
7
8
/**
9
 * Class DefaultMethodResolver
10
 */
11
class DefaultMethodResolver implements MethodResolverInterface
12
{
13
    /** @var JsonRpcMethodInterface[] */
14
    private $methodList = [];
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function resolve(string $methodName) : JsonRpcMethodInterface
19
    {
20
        // TODO: Implement resolve() method.
21
        if (!isset($this->methodList[$methodName])) {
22
            throw new JsonRpcMethodNotFoundException($methodName);
23
        }
24
25
        return $this->methodList[$methodName];
26
    }
27
28
    /**
29
     * @param string                 $methodName
30
     * @param JsonRpcMethodInterface $method
31
     */
32
    public function addMethod(string $methodName, JsonRpcMethodInterface $method)
33
    {
34
        $this->methodList[$methodName] = $method;
35
    }
36
}
37