Test Setup Failed
Push — release/2.5.x ( 561eb6...9a29e9 )
by
unknown
06:54 queued 03:10
created

AbstractAdminAwareVoter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B vote() 0 18 5
1
<?php
2
/**
3
 * @author Rik van der Kemp <[email protected]>
4
 * @copyright Zicht Online <http://www.zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\PageBundle\Security\Voter;
8
9
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
10
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
11
12
/**
13
 * Checks on 'vote' whether or not the current user is and admin
14
 *
15
 * @package Zicht\Bundle\PageBundle\Security\Voter
16
 */
17
abstract class AbstractAdminAwareVoter extends AbstractVoter
18
{
19
    /**
20
     * Returns the vote for the given parameters.
21
     *
22
     * This method must return one of the following constants:
23
     * ACCESS_GRANTED, ACCESS_DENIED, or ACCESS_ABSTAIN.
24
     *
25
     * @param TokenInterface $token A TokenInterface instance
26
     * @param object $object The object to secure
27
     * @param array $attributes An array of attributes associated with the method being invoked
28
     *
29
     * @return integer either ACCESS_GRANTED, ACCESS_ABSTAIN, or ACCESS_DENIED
30
     */
31
    public function vote(TokenInterface $token, $object, array $attributes)
32
    {
33
        /**
34
         * Admin users should see content no matter the scheduled dates
35
         * Since you can set the decision strategy to unanimous, you want to grant this explicitly
36
         */
37
        if ($this->supportsClass(get_class($object)) && sizeof($token->getRoles())) {
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Securi...erface::supportsClass() has been deprecated with message: since version 2.8, to be removed in 3.0.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
38
            /** @var \Symfony\Component\Security\Core\Role\Role $role */
39
            foreach ($token->getRoles() as $role) {
40
                if (in_array($role->getRole(), array('ROLE_ADMIN', 'ROLE_SUPER_ADMIN'))) {
41
                    return VoterInterface::ACCESS_GRANTED;
42
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
43
                }
44
            }
45
        }
46
47
        return VoterInterface::ACCESS_ABSTAIN;
48
    }
49
}
50