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

PageVoter::supportsAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * @author Rik van der Kemp <[email protected]>
4
 * @copyright Zicht Online <http://www.zicht.nl>
5
 */
6
namespace Zicht\Bundle\PageBundle\Security\Voter;
7
8
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
9
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
10
use Zicht\Bundle\PageBundle\Model\PageInterface;
11
12
/**
13
 * Votes for pages to be public for anyone.
14
 */
15
class PageVoter extends AbstractVoter
16
{
17
    /**
18
     * @{inheritDoc}
19
     */
20
    public function supportsClass($class)
21
    {
22
        $supportedClass = 'Zicht\Bundle\PageBundle\Entity\Page';
23
24
        return $supportedClass === $class || is_subclass_of($class, $supportedClass);
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if $supportedClass can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
25
    }
26
27
    /**
28
     * @{inheritDoc}
29
     */
30
    public function vote(TokenInterface $token, $object, array $attributes)
31
    {
32
        // check if class of this object is supported by this voter
33
        if (!$this->supportsClass(get_class($object))) {
34
            return VoterInterface::ACCESS_ABSTAIN;
35
        }
36
37
        foreach ($attributes as $attribute) {
38
            if (!$this->supportsAttribute($attribute)) {
39
                continue;
40
            }
41
42
            if ($this->isPublic($object)) {
0 ignored issues
show
Documentation introduced by
$object is of type object|null, but the function expects a object<Zicht\Bundle\Page...le\Model\PageInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
                return VoterInterface::ACCESS_GRANTED;
44
            }
45
        }
46
        return VoterInterface::ACCESS_ABSTAIN;
47
    }
48
49
50
    /**
51
     * Checks whether the given page is public. If not, it abstains from voting
52
     *
53
     * @param PageInterface $page
54
     * @return bool
55
     */
56
    public function isPublic(PageInterface $page)
57
    {
58
        return $page->isPublic();
59
    }
60
}
61