CheckRequirementsSubscriber::onPresenter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symnedi.
7
 * Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz)
8
 */
9
10
namespace Symnedi\Security\EventSubscriber;
11
12
use Nette\Application\UI\ComponentReflection;
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
15
use Symnedi\EventDispatcher\Event\ApplicationPresenterEvent;
16
use Symnedi\EventDispatcher\NetteApplicationEvents;
17
18
final class CheckRequirementsSubscriber implements EventSubscriberInterface
19
{
20
    /**
21
     * @var AuthorizationCheckerInterface
22
     */
23
    private $authorizationChecker;
24
25 1
    public function __construct(AuthorizationCheckerInterface $authorizationChecker)
26
    {
27 1
        $this->authorizationChecker = $authorizationChecker;
28 1
    }
29
30 1
    public static function getSubscribedEvents() : array
31
    {
32
        return [
33 1
            NetteApplicationEvents::ON_PRESENTER => 'onPresenter',
34
        ];
35
    }
36
37 1
    public function onPresenter(ApplicationPresenterEvent $applicationPresenterEvent)
38
    {
39 1
        $this->authorizationChecker->isGranted(
40 1
            'access',
41 1
            new ComponentReflection($applicationPresenterEvent->getPresenter())
42
        );
43 1
    }
44
}
45