IndexController::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 7
cp 0
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ApiSkeleton\Controller;
6
7
use Chubbyphp\ApiHttp\Manager\RequestManagerInterface;
8
use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface;
9
use Psr\Http\Message\ServerRequestInterface as Request;
10
use Psr\Http\Message\ResponseInterface as Response;
11
use Chubbyphp\ApiSkeleton\Search\Index;
12
13
final class IndexController
14
{
15
    /**
16
     * @var RequestManagerInterface
17
     */
18
    private $requestManager;
19
20
    /**
21
     * @var ResponseManagerInterface
22
     */
23
    private $responseManager;
24
25
    /**
26
     * @param RequestManagerInterface  $requestManager
27
     * @param ResponseManagerInterface $responseManager
28
     */
29
    public function __construct(RequestManagerInterface $requestManager, ResponseManagerInterface $responseManager)
30
    {
31
        $this->requestManager = $requestManager;
32
        $this->responseManager = $responseManager;
33
    }
34
35
    /**
36
     * @param Request $request
37
     *
38
     * @return Response
39
     */
40
    public function __invoke(Request $request)
41
    {
42
        if (null === $accept = $this->requestManager->getAccept($request)) {
43
            return $this->responseManager->createAcceptNotSupportedResponse($request);
44
        }
45
46
        return $this->responseManager->createResponse($request, 200, $accept, new Index());
47
    }
48
}
49