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 |
||
8 | class Rule extends \ArrayObject |
||
9 | { |
||
10 | use EntityTrait; |
||
11 | |||
12 | /** |
||
13 | * @param array $array |
||
14 | */ |
||
15 | public function __construct(array $array = []) |
||
19 | |||
20 | /** |
||
21 | * Sets the 'id' parameter. |
||
22 | * |
||
23 | * @param string $id |
||
24 | * |
||
25 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
26 | * |
||
27 | * @return \Acquia\LiftClient\Entity\Rule |
||
28 | */ |
||
29 | View Code Duplication | public function setId($id) |
|
38 | |||
39 | /** |
||
40 | * Gets the 'id' parameter. |
||
41 | * |
||
42 | * @return string The Identifier of the Rule |
||
43 | */ |
||
44 | public function getId() |
||
48 | |||
49 | /** |
||
50 | * Sets the 'label' parameter. |
||
51 | * |
||
52 | * @param string $label |
||
53 | * |
||
54 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
55 | * |
||
56 | * @return \Acquia\LiftClient\Entity\Rule |
||
57 | */ |
||
58 | View Code Duplication | public function setLabel($label) |
|
67 | |||
68 | /** |
||
69 | * Gets the 'label' parameter. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getLabel() |
||
77 | |||
78 | /** |
||
79 | * Sets the 'description' parameter. |
||
80 | * |
||
81 | * @param string $description |
||
82 | * |
||
83 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
84 | * |
||
85 | * @return \Acquia\LiftClient\Entity\Rule |
||
86 | */ |
||
87 | View Code Duplication | public function setDescription($description) |
|
96 | |||
97 | /** |
||
98 | * Gets the 'description' parameter. |
||
99 | * |
||
100 | * @return string The Description of the Rule |
||
101 | */ |
||
102 | public function getDescription() |
||
106 | |||
107 | /** |
||
108 | * Sets the 'slot_id' parameter. |
||
109 | * |
||
110 | * @param string $slotId |
||
111 | * |
||
112 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
113 | * |
||
114 | * @return \Acquia\LiftClient\Entity\Rule |
||
115 | */ |
||
116 | public function setSlotId($slotId) |
||
125 | |||
126 | /** |
||
127 | * Gets the 'description' parameter. |
||
128 | * |
||
129 | * @return string The Description of the Rule |
||
130 | */ |
||
131 | public function getSlotId() |
||
135 | |||
136 | /** |
||
137 | * Sets the 'weight' parameter. |
||
138 | * |
||
139 | * @param int $weight |
||
140 | * |
||
141 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
142 | * |
||
143 | * @return \Acquia\LiftClient\Entity\Rule |
||
144 | */ |
||
145 | public function setWeight($weight) |
||
154 | |||
155 | /** |
||
156 | * Gets the 'description' parameter. |
||
157 | * |
||
158 | * @return int The Description of the Rule |
||
159 | */ |
||
160 | public function getWeight() |
||
164 | |||
165 | /** |
||
166 | * Sets the 'content' parameter. |
||
167 | * |
||
168 | * @param Content[] $contentList |
||
169 | * |
||
170 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
171 | * |
||
172 | * @return \Acquia\LiftClient\Entity\Rule |
||
173 | */ |
||
174 | public function setContent(array $contentList) |
||
184 | |||
185 | /** |
||
186 | * Gets the 'content' parameter. |
||
187 | * |
||
188 | * @return Content[] The list of content this rule applies to |
||
189 | */ |
||
190 | public function getContent() |
||
200 | |||
201 | /** |
||
202 | * Sets the 'segment' parameter. |
||
203 | * |
||
204 | * @param string $segment |
||
205 | * |
||
206 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
207 | * |
||
208 | * @return \Acquia\LiftClient\Entity\Rule |
||
209 | */ |
||
210 | View Code Duplication | public function setSegment($segment) |
|
219 | |||
220 | /** |
||
221 | * Gets the 'segment' parameter. |
||
222 | * |
||
223 | * @return string |
||
224 | */ |
||
225 | public function getSegment() |
||
229 | |||
230 | /** |
||
231 | * Sets the 'status' parameter. |
||
232 | * |
||
233 | * @param string $status |
||
234 | * |
||
235 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
236 | * |
||
237 | * @return \Acquia\LiftClient\Entity\Rule |
||
238 | */ |
||
239 | public function setStatus($status) |
||
251 | |||
252 | /** |
||
253 | * Gets the 'status' parameter. |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | public function getStatus() |
||
261 | |||
262 | /** |
||
263 | * Gets the 'created' parameter. |
||
264 | * |
||
265 | * @return DateTime |
||
266 | */ |
||
267 | public function getCreated() |
||
274 | |||
275 | /** |
||
276 | * Gets the 'updated' parameter. |
||
277 | * |
||
278 | * @return DateTime |
||
279 | */ |
||
280 | public function getUpdated() |
||
287 | |||
288 | /** |
||
289 | * Sets the Rule test_config property. |
||
290 | * |
||
291 | * @param \Acquia\LiftClient\Entity\TestConfigInterface $testConfig |
||
292 | * |
||
293 | * @return \Acquia\LiftClient\Entity\Rule |
||
294 | */ |
||
295 | public function setTestConfig(TestConfigInterface $testConfig) |
||
321 | |||
322 | /** |
||
323 | * Gets the 'test_config' parameter. |
||
324 | * |
||
325 | * @return \Acquia\LiftClient\Entity\TestConfigInterface|null $testConfig |
||
326 | */ |
||
327 | public function getTestConfig() |
||
349 | } |
||
350 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.