Passed
Pull Request — release/3.x (#24)
by
unknown
07:12
created

AbstractAdminAwareVoter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 4
cts 10
cp 0.4
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B vote() 0 20 6
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 7
    public function vote(TokenInterface $token, $object, array $attributes)
32
    {
33 7
        if (null === $object) {
34
            return VoterInterface::ACCESS_ABSTAIN;
35
        }
36
37
        /**
38
         * Admin users should see content no matter the scheduled dates
39
         * Since you can set the decision strategy to unanimous, you want to grant this explicitly
40
         */
41 7
        if ($this->supportsClass(get_class($object)) && sizeof($token->getRoles())) {
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Securi...erface::supportsClass() has been deprecated: since version 2.8, to be removed in 3.0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

41
        if (/** @scrutinizer ignore-deprecated */ $this->supportsClass(get_class($object)) && sizeof($token->getRoles())) {

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

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

Loading history...
42
            /** @var \Symfony\Component\Security\Core\Role\Role $role */
43
            foreach ($token->getRoles() as $role) {
44
                if (in_array($role->getRole(), array('ROLE_ADMIN', 'ROLE_SUPER_ADMIN'))) {
45
                    return VoterInterface::ACCESS_GRANTED;
46
                }
47
            }
48
        }
49
50 7
        return VoterInterface::ACCESS_ABSTAIN;
51
    }
52
}
53