Completed
Pull Request — feature/array-method-resolver (#19)
by Yo
01:59
created

ArrayMethodResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addMethod() 0 5 1
A resolve() 0 5 2
1
<?php
2
namespace Yoanm\JsonRpcServer\Infra\Resolver;
3
4
use Yoanm\JsonRpcServer\Domain\Model\JsonRpcMethodInterface;
5
use Yoanm\JsonRpcServer\Domain\Model\MethodResolverInterface;
6
7
/**
8
 * Class ArrayMethodResolver
9
 */
10
class ArrayMethodResolver implements MethodResolverInterface
11
{
12
    /** @var JsonRpcMethodInterface[] */
13
    private $methodList = [];
14
15
    /**
16
     * {@inheritdoc}
17
     */
18 2
    public function resolve(string $methodName)
19
    {
20 2
        return array_key_exists($methodName, $this->methodList)
21 1
            ? $this->methodList[$methodName]
22 2
            : null
23
        ;
24
    }
25
26
    /**
27
     * @param JsonRpcMethodInterface $method
28
     * @param string                 $methodName
29
     *
30
     * @return ArrayMethodResolver
31
     */
32 2
    public function addMethod(JsonRpcMethodInterface $method, string $methodName) : ArrayMethodResolver
33
    {
34 2
        $this->methodList[$methodName] = $method;
35
36 2
        return $this;
37
    }
38
}
39