Failed Conditions
Pull Request — feature/array-method-resolver (#19)
by Yo
02:36
created

ArrayMethodResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
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
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