Completed
Pull Request — master (#1)
by Yo
02:47
created

JsonRpcHttpEndpoint   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 18
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\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