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

JsonRpcHttpEndpoint::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
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