SsrRenderSubscriber   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 51
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onKernelView() 0 19 3
A getSubscribedEvents() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: polidog
5
 * Date: 2017/02/21.
6
 */
7
8
namespace Polidog\SsrBundle\EventListener;
9
10
use Polidog\SsrBundle\Annotations\Ssr;
11
use Polidog\SsrBundle\Render\SsrRenderInterface;
12
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13
use Symfony\Component\HttpFoundation\Response;
14
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
15
use Symfony\Component\HttpKernel\KernelEvents;
16
17
class SsrRenderSubscriber implements EventSubscriberInterface
18
{
19
    /**
20
     * @var SsrRenderInterface
21
     */
22
    protected $ssrRender;
23
24
    /**
25
     * @var SsrRenderInterface
26
     */
27
    protected $cacheSsrRender;
28
29
    /**
30
     * SsrRenderSubscriber constructor.
31
     *
32
     * @param SsrRenderInterface $ssrRender
33
     * @param SsrRenderInterface $cacheSsrRender
34
     */
35
    public function __construct(SsrRenderInterface $ssrRender, SsrRenderInterface $cacheSsrRender)
36
    {
37
        $this->ssrRender = $ssrRender;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
38
        $this->cacheSsrRender = $cacheSsrRender;
39
    }
40
41
    public function onKernelView(GetResponseForControllerResultEvent $event)
42
    {
43
        $request = $event->getRequest();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
44
        $response = $event->getResponse();
45
46
        /** @var Ssr $ssr */
47
        $ssr = $request->attributes->get('_ssr');
48
        if ($ssr->isCache()) {
49
            $content = $this->cacheSsrRender->render($ssr, $event->getControllerResult());
50
        } else {
51
            $content = $this->ssrRender->render($ssr, $event->getControllerResult());
52
        }
53
54
        if (null === $response) {
55
            $response = new Response();
56
        }
57
        $response->setContent($content);
58
        $event->setResponse($response);
59
    }
60
61
    public static function getSubscribedEvents()
62
    {
63
        return [
64
            KernelEvents::VIEW => 'onKernelView',
65
        ];
66
    }
67
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
68