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

ControllerSubscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 26
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A registerCurrentController() 0 9 2
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