HasRoles::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Yokai\SecurityExtraBundle\Callback;
4
5
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
6
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
7
8
/**
9
 * @author Yann Eugoné <[email protected]>
10
 */
11
class HasRoles
12
{
13
    /**
14
     * Symfony's Security decision manager
15
     * @var AccessDecisionManagerInterface
16
     */
17
    private $decisionManager;
18
19
    /**
20
     * The roles that must be accessible.
21
     * @var string[]
22
     */
23
    private $roles;
24
25
    /**
26
     * @param AccessDecisionManagerInterface $decisionManager The role hierarchy
27
     * @param string[]               $roles         The roles that must be accessible
28
     */
29 2
    public function __construct(AccessDecisionManagerInterface $decisionManager, $roles)
30
    {
31 2
        $this->decisionManager = $decisionManager;
32 2
        $this->roles = $roles;
33 2
    }
34
35
    /**
36
     * Check if the provided token has access to every configured roles.
37
     *
38
     * @param TokenInterface $token The security token
39
     *
40
     * @return bool Whether or not token has all configured roles
41
     */
42 2
    public function __invoke(TokenInterface $token)
43
    {
44 2
        return $this->decisionManager->decide($token, $this->roles);
45
    }
46
}
47