Completed
Push — master ( c114e4...0fa665 )
by Eric
9s
created

SecurityChecker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Bundle\ResourceBundle\Security;
13
14
use Lug\Bundle\ResourceBundle\Routing\ParameterResolverInterface;
15
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class SecurityChecker implements SecurityCheckerInterface
21
{
22
    /**
23
     * @var AuthorizationCheckerInterface
24
     */
25
    private $authorizationChecker;
26
27
    /**
28
     * @var ParameterResolverInterface
29
     */
30
    private $parameterResolver;
31
32
    /**
33
     * @param AuthorizationCheckerInterface $authorizationChecker
34
     * @param ParameterResolverInterface    $parameterResolver
35
     */
36 4
    public function __construct(
37
        AuthorizationCheckerInterface $authorizationChecker,
38
        ParameterResolverInterface $parameterResolver
39
    ) {
40 4
        $this->authorizationChecker = $authorizationChecker;
41 4
        $this->parameterResolver = $parameterResolver;
42 4
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 2
    public function isGranted($action, $object)
48
    {
49 2
        if (!$this->parameterResolver->resolveVoter()) {
50 1
            return true;
51
        }
52
53 1
        return $this->authorizationChecker->isGranted('lug.'.$action, $object);
54
    }
55
}
56