IndexController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 8 2
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