Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
21 | class Role extends AbstractModel |
||
|
|||
22 | { |
||
23 | use TranslatorAwareTrait; |
||
24 | |||
25 | const SEPARATOR = ','; |
||
26 | |||
27 | /** |
||
28 | * @var string|null $ident |
||
29 | */ |
||
30 | public $ident; |
||
31 | |||
32 | /** |
||
33 | * The parent ACL role. |
||
34 | * |
||
35 | * This role will inherit all of its parent's permissions. |
||
36 | * |
||
37 | * @var string $parent |
||
38 | */ |
||
39 | public $parent; |
||
40 | |||
41 | /** |
||
42 | * The user-friendly name. |
||
43 | * |
||
44 | * @var \Charcoal\Translator\Translation |
||
45 | */ |
||
46 | public $name; |
||
47 | |||
48 | /** |
||
49 | * List of explicitely allowed permissions. |
||
50 | * |
||
51 | * @var string[]|null $allowed |
||
52 | */ |
||
53 | public $allowed; |
||
54 | |||
55 | /** |
||
56 | * List of explicitely denied permissions. |
||
57 | * |
||
58 | * @var string[]|null $denied |
||
59 | */ |
||
60 | public $denied; |
||
61 | |||
62 | /** |
||
63 | * @var boolean |
||
64 | */ |
||
65 | private $superuser = false; |
||
66 | |||
67 | /** |
||
68 | * @var integer |
||
69 | */ |
||
70 | private $position; |
||
71 | |||
72 | /** |
||
73 | * ACL Role can be used as a string (ident). |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function __toString() |
||
84 | |||
85 | /** |
||
86 | * @return string |
||
87 | */ |
||
88 | public function key() |
||
92 | |||
93 | /** |
||
94 | * @param string|Role $parent Role's parent. |
||
95 | * @return self |
||
96 | */ |
||
97 | public function setParent($parent) |
||
102 | |||
103 | /** |
||
104 | * @return string |
||
105 | */ |
||
106 | public function getParent() |
||
107 | { |
||
108 | return $this->parent; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @param string[]|string|null $allowed The allowed permissions for this role. |
||
113 | * @throws InvalidArgumentException If the passed arguments is not an array, null, or a comma-separated string. |
||
114 | * @return self |
||
115 | */ |
||
116 | View Code Duplication | public function setAllowed($allowed) |
|
135 | |||
136 | /** |
||
137 | * @return string[]|null |
||
138 | */ |
||
139 | public function getAllowed() |
||
140 | { |
||
141 | return $this->allowed; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @param string[]|string|null $denied The denied permissions for this role. |
||
146 | * @throws InvalidArgumentException If the passed arguments is not an array, null, or a comma-separated string. |
||
147 | * @return self |
||
148 | */ |
||
149 | View Code Duplication | public function setDenied($denied) |
|
168 | |||
169 | /** |
||
170 | * @return string[]|null |
||
171 | */ |
||
172 | public function getDenied() |
||
173 | { |
||
174 | return $this->denied; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * @param boolean $isSuper The superuser flag. |
||
179 | * @return self |
||
180 | */ |
||
181 | public function setSuperuser($isSuper) |
||
186 | |||
187 | /** |
||
188 | * @return boolean |
||
189 | */ |
||
190 | public function getSuperuser() |
||
191 | { |
||
192 | return $this->superuser; |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * @param integer|string|null $position The role's ordering position. |
||
197 | * @return self |
||
198 | */ |
||
199 | public function setPosition($position) |
||
204 | |||
205 | /** |
||
206 | * @return integer |
||
207 | */ |
||
208 | public function getPosition() |
||
209 | { |
||
210 | return $this->position; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * @param Container $container Pimple DI container. |
||
215 | * @return void |
||
216 | */ |
||
217 | protected function setDependencies(Container $container) |
||
223 | } |
||
224 |