AbstractVoter::hasCmsAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
1
<?php
2
/**
3
 * @author    Philip Bergman <[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
10
/**
11
 * Class AbstractVoter
12
 *
13
 * @package Zicht\Bundle\PageBundle\Security\Voter
14
 */
15
abstract class AbstractVoter implements VoterInterface
16
{
17
    const SUPPORTED_ATTRIBUTES = ['VIEW', 'ACTION_POST_UPDATE', 'ACTION_POST_PERSIST'];
18
19
    /**
20
     * @{inheritDoc}
21
     */
22 6
    public function supportsAttribute($attribute)
23
    {
24 6
        return in_array($attribute, self::SUPPORTED_ATTRIBUTES);
25
    }
26
27
    /**
28
     * Check if one or more of the given items is not empty
29
     *
30
     * @param ...$value
31
     * @return bool
32
     */
33 6
    protected static function notEmpty(...$value)
34
    {
35 6
        return (bool)count(array_filter($value)) >= 1;
36
    }
37
38
    /**
39
     * Check if the given attributes contain cms roles/attributes
40
     *
41
     * @param array $attributes
42
     * @return bool
43
     */
44 1
    protected static function hasCmsAttribute(array $attributes = [])
45
    {
46 1
        return (in_array('ACTION_POST_UPDATE', $attributes) || in_array('ACTION_POST_PERSIST', $attributes));
47
    }
48
}