Completed
Pull Request — master (#343)
by Leny
22:37
created

PageDebugVoter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A supports() 0 4 2
A voteOnAttribute() 0 4 2
1
<?php
2
3
namespace Victoire\Bundle\PageBundle\Security\Voter;
4
5
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
6
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
7
8
/**
9
 * This class decides yes or no if the user is granted to see the debug.
10
 */
11
class PageDebugVoter extends Voter
12
{
13
    protected $userClass;
14
15
    /**
16
     * Constructor.
17
     *
18
     * @param string $userClass
19
     */
20
    public function __construct($userClass)
21
    {
22
        $this->userClass = $userClass;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function supports($attribute, $subject)
29
    {
30
        return null != $subject && 'PAGE_DEBUG' === $attribute;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
37
    {
38
        return $token->getUser() instanceof $this->userClass && $token->getUser()->hasRole('ROLE_VICTOIRE');
39
    }
40
}
41