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

AbstractAdminAwareVoter::vote()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 11.1035

Importance

Changes 0
Metric Value
cc 5
eloc 5
c 0
b 0
f 0
nc 3
nop 3
dl 0
loc 16
ccs 3
cts 8
cp 0.375
crap 11.1035
rs 8.8571
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
        /**
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 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

37
        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...
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
                }
43
            }
44
        }
45
46 7
        return VoterInterface::ACCESS_ABSTAIN;
47
    }
48
}
49