Passed
Push — master ( be1c28...682c63 )
by Yo
02:02
created

JsonRpcHttpEndpoint::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
namespace Yoanm\SymfonyJsonRpcHttpServer\Infra\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 2
    public function __construct(SDKJsonRpcEndpoint $sdkEndpoint)
17
    {
18 2
        $this->sdkEndpoint = $sdkEndpoint;
19 2
    }
20
21 2
    public function index(Request $request) : Response
22
    {
23 2
        if (Request::METHOD_POST !== $request->getMethod()) {
24 1
            return new Response('A JSON-RPC HTTP call must use POST', Response::HTTP_METHOD_NOT_ALLOWED);
25
        }
26
27 1
        return new Response(
28 1
            $this->sdkEndpoint->index($request->getContent())
29
        );
30
    }
31
}
32