Passed
Push — fix_coverage_in_scrutinizer ( cd0379...a04ba4 )
by Herberto
13:22
created

ControllerSubscriber::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\EventSubscriber;
13
14
use App\Twig\SourceCodeExtension;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
17
use Symfony\Component\HttpKernel\KernelEvents;
18
19
/**
20
 * Defines the method that 'listens' to the 'kernel.controller' event, which is
21
 * triggered whenever a controller is executed in the application.
22
 *
23
 * @author Ryan Weaver <[email protected]>
24
 * @author Javier Eguiluz <[email protected]>
25
 */
26
class ControllerSubscriber implements EventSubscriberInterface
27
{
28
    private $twigExtension;
29
30 16
    public function __construct(SourceCodeExtension $twigExtension)
31
    {
32 16
        $this->twigExtension = $twigExtension;
33 16
    }
34
35 1
    public static function getSubscribedEvents(): array
36
    {
37
        return [
38 1
            KernelEvents::CONTROLLER => 'registerCurrentController',
39
        ];
40
    }
41
42 16
    public function registerCurrentController(FilterControllerEvent $event): void
43
    {
44
        // this check is needed because in Symfony a request can perform any
45
        // number of sub-requests. See
46
        // https://symfony.com/doc/current/components/http_kernel/introduction.html#sub-requests
47 16
        if ($event->isMasterRequest()) {
48 12
            $this->twigExtension->setController($event->getController());
49
        }
50 16
    }
51
}
52