ServerFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
c 2
b 1
f 0
lcom 0
cbo 8
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 16 2
1
<?php
2
3
namespace Tonic\Component\ApiLayer\JsonRpc;
4
5
use Tonic\Component\ApiLayer\JsonRpc\Method\ArgumentMapper\ArgumentMapper;
6
use Tonic\Component\ApiLayer\JsonRpc\Method\ArgumentMapper\Normalizer\Normalizer;
7
use Tonic\Component\ApiLayer\JsonRpc\Method\Loader\LoaderInterface;
8
use Tonic\Component\ApiLayer\JsonRpc\Method\MethodDispatcher;
9
use Tonic\Component\ApiLayer\JsonRpc\Method\MethodInvoker;
10
use Tonic\Component\ApiLayer\JsonRpc\Method\MethodInvokerInterface;
11
use Tonic\Component\ApiLayer\JsonRpc\Request\RequestParser;
12
use Tonic\Component\ApiLayer\JsonRpc\Response\ErrorResponseFactory;
13
use Tonic\Component\ApiLayer\JsonRpc\Response\ResponseSerializer;
14
15
/**
16
 * Creates preconfigured server instance.
17
 */
18
class ServerFactory
19
{
20
    /**
21
     * @param LoaderInterface             $loader
22
     * @param MethodInvokerInterface|null $methodInvoker
23
     * @param bool                        $exposeInternalExceptions
24
     *
25
     * @return Server
26
     */
27
    public function create(
28
        LoaderInterface $loader,
29
        MethodInvokerInterface $methodInvoker = null,
30
        $exposeInternalExceptions = false
31
    ) {
32
        if (null === $methodInvoker) {
33
            $methodInvoker = new MethodInvoker();
34
        }
35
36
        return new Server(
37
            new RequestParser(),
38
            new MethodDispatcher($loader, new ArgumentMapper(new Normalizer()), $methodInvoker),
39
            new ResponseSerializer(),
40
            new ErrorResponseFactory($exposeInternalExceptions)
41
        );
42
    }
43
}
44