Passed
Push — develop ( 355f63...51016a )
by Mathieu
02:23
created

Access   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neimheadh\SonataAnnotationBundle\Annotation\Sonata;
6
7
use Attribute;
8
use Neimheadh\SonataAnnotationBundle\Annotation\AbstractAnnotation;
9
use ReflectionException;
10
11
/**
12
 * Access control annotation.
13
 *
14
 * Allow you to control permission per role.
15
 *
16
 * @Annotation
17
 * @Target("CLASS")
18
 *
19
 * @author Marko Kunic <[email protected]>
20
 * @author Mathieu Wambre <[email protected]>
21
 */
22
#[Attribute(Attribute::TARGET_CLASS)]
23
final class Access extends AbstractAnnotation
24
{
25
26
    /**
27
     * Allowed role.
28
     *
29
     * @var string|null
30
     */
31
    public ?string $role = null;
32
33
    /**
34
     * Allowed permissions.
35
     *
36
     * @var array
37
     */
38
    public array $permissions = [];
39
40
    /**
41
     * @param array|string|null $role        Allowed role or annotation
42
     *                                       parameters.
43
     * @param array             $permissions Allowed permissions.
44
     *
45
     * @throws ReflectionException
46
     */
47
    public function __construct(
48
        $role = null,
49
        array $permissions = []
50
    ) {
51
        $this->permissions = $permissions;
52
53
        if (is_array($role)) {
54
            $this->initAnnotation($role);
55
        } else {
56
            $this->role = $role;
57
        }
58
    }
59
60
}
61