Completed
Pull Request — dev (#24)
by Arnaud
02:59
created

Action::getPermissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace LAG\AdminBundle\Action;
4
5
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
6
use LAG\AdminBundle\Admin\Filter;
7
use LAG\AdminBundle\Field\Field;
8
9
class Action implements ActionInterface
10
{
11
    /**
12
     * Action name.
13
     *
14
     * @var string
15
     */
16
    protected $name;
17
18
    /**
19
     * Action title.
20
     *
21
     * @var string
22
     */
23
    protected $title;
24
25
    /**
26
     * Fields displayed for this action.
27
     *
28
     * @var Field[]
29
     */
30
    protected $fields = [];
31
32
    /**
33
     * Action permissions.
34
     *
35
     * @var string[]
36
     */
37
    protected $permissions = [];
38
39
    /**
40
     * @var ActionConfiguration
41
     */
42
    protected $configuration;
43
44
    /**
45
     * @var array
46
     */
47
    protected $filters = [];
48
49
    /**
50
     * Action constructor.
51
     *
52
     * @param string $actionName
53
     * @param ActionConfiguration $configuration
54
     */
55
    public function __construct($actionName, ActionConfiguration $configuration)
56
    {
57
        $this->configuration = $configuration;
58
        $this->name = $actionName;
59
        $this->title = $configuration->getParameter('title');
60
        $this->permissions = $configuration->getParameter('permissions');
1 ignored issue
show
Documentation Bug introduced by
It seems like $configuration->getParameter('permissions') of type * is incompatible with the declared type array<integer,string> of property $permissions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getName()
67
    {
68
        return $this->name;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getTitle()
75
    {
76
        return $this->title;
77
    }
78
79
    /**
80
     * @return Field[]
81
     */
82
    public function getFields()
83
    {
84
        return $this->fields;
85
    }
86
87
    /**
88
     * Return true if action has a field named $fieldName.
89
     *
90
     * @param string $fieldName
91
     *
92
     * @return bool
93
     */
94
    public function hasField($fieldName)
95
    {
96
        return array_key_exists($fieldName, $this->fields);
97
    }
98
99
    /**
100
     * @param Field[] $fields
101
     */
102
    public function setFields($fields)
103
    {
104
        $this->fields = $fields;
105
    }
106
107
    /**
108
     * @param Field $field
109
     */
110
    public function addField(Field $field)
111
    {
112
        $this->fields[$field->getName()] = $field;
113
    }
114
115
    /**
116
     * @return string[]
117
     */
118
    public function getPermissions()
119
    {
120
        return $this->permissions;
121
    }
122
123
    /**
124
     * @return array
125
     */
126
    public function getFilters()
127
    {
128
        return $this->filters;
129
    }
130
131
    /**
132
     * @param array $filters
133
     */
134
    public function setFilters($filters)
135
    {
136
        $this->filters = $filters;
137
    }
138
139
    /**
140
     * @param Filter $filter
141
     */
142
    public function addFilter(Filter $filter)
143
    {
144
        $this->filters[] = $filter;
145
    }
146
    
147
    /**
148
     * @return ActionConfiguration
149
     */
150
    public function getConfiguration()
151
    {
152
        return $this->configuration;
153
    }
154
}
155