Completed
Push — master ( 23464b...caaf65 )
by Yo
01:52
created

JsonRpcHttpEndpoint   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A index() 0 8 2
1
<?php
2
namespace Yoanm\SymfonyJsonRpcHttpServer\Endpoint;
3
4
use Symfony\Component\HttpFoundation\Request;
5
use Symfony\Component\HttpFoundation\Response;
6
use Yoanm\JsonRpcServer\Infra\Endpoint\JsonRpcEndpoint as SDKJsonRpcEndpoint;
7
8
/**
9
 * Class JsonRpcHttpEndpoint
10
 */
11
class JsonRpcHttpEndpoint
12
{
13
    /** @var SdkJsonRpcEndpoint */
14
    private $sdkEndpoint;
15
16
    /**
17
     * @param SDKJsonRpcEndpoint $sdkEndpoint
18
     */
19 2
    public function __construct(SDKJsonRpcEndpoint $sdkEndpoint)
20
    {
21 2
        $this->sdkEndpoint = $sdkEndpoint;
22 2
    }
23
24
    /**
25
     * @param Request $request
26
     *
27
     * @return Response
28
     */
29 2
    public function index(Request $request) : Response
30
    {
31 2
        if (Request::METHOD_POST !== $request->getMethod()) {
32 1
            return new Response('A JSON-RPC HTTP call must use POST', Response::HTTP_METHOD_NOT_ALLOWED);
33
        }
34
35 1
        return new Response(
36 1
            $this->sdkEndpoint->index($request->getContent())
37
        );
38
    }
39
}
40