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

AbstractVoter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsAttribute() 0 4 1
A notEmpty() 0 4 1
A hasCmsAttribute() 0 4 2
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
    public function supportsAttribute($attribute)
23
    {
24
        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
    protected static function notEmpty(...$value)
34
    {
35
        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
    protected static function hasCmsAttribute(array $attributes = [])
45
    {
46
        return (in_array('ACTION_POST_UPDATE', $attributes) || in_array('ACTION_POST_PERSIST', $attributes));
47
    }
48
}