HttpFoundationResponder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 39
ccs 11
cts 13
cp 0.8462
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createResponse() 0 17 2
A __construct() 0 3 1
1
<?php
2
3
namespace Lamoda\Metric\MetricBundle\Controller;
4
5
use Lamoda\Metric\Responder\PsrResponder;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\HttpKernel\Exception\HttpException;
8
9
final class HttpFoundationResponder
10
{
11
    /** @var PsrResponder */
12
    private $psrResponder;
13
14
    /**
15
     * ResponderController constructor.
16
     *
17
     * @param PsrResponder $psrResponder
18
     */
19 1
    public function __construct(PsrResponder $psrResponder)
20
    {
21 1
        $this->psrResponder = $psrResponder;
22 1
    }
23
24
    /**
25
     * Create HTTP-Kernel response for collected
26
     *
27
     * @return Response
28
     *
29
     * @throws HttpException
30
     */
31 1
    public function createResponse(): Response
32
    {
33
        try {
34 1
            $response = $this->psrResponder->createResponse();
35
36 1
            $symfonyResponse = new Response(
37 1
                (string) $response->getBody(),
38 1
                $response->getStatusCode(),
39 1
                $response->getHeaders()
40
            );
41
        } catch (\Exception $exception) {
42
            throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, null, $exception);
43
        }
44
45 1
        $symfonyResponse->setPrivate();
46
47 1
        return $symfonyResponse;
48
    }
49
}
50