Completed
Pull Request — master (#343)
by Leny
10:06
created

PageDebugVoter::vote()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 8.8571
cc 6
eloc 9
nc 4
nop 3
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