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 Goal 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\Goal |
||
28 | */ |
||
29 | View Code Duplication | public function setId($id) |
|
38 | |||
39 | /** |
||
40 | * Gets the 'id' parameter. |
||
41 | * |
||
42 | * @return string The Identifier of the Goal |
||
43 | */ |
||
44 | public function getId() |
||
48 | |||
49 | /** |
||
50 | * Sets the 'name' parameter. |
||
51 | * |
||
52 | * @param string $name |
||
53 | * |
||
54 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
55 | * |
||
56 | * @return \Acquia\LiftClient\Entity\Goal |
||
57 | */ |
||
58 | View Code Duplication | public function setName($name) |
|
67 | |||
68 | /** |
||
69 | * Gets the 'name' parameter. |
||
70 | * |
||
71 | * @return string The Name of the Goal |
||
72 | */ |
||
73 | public function getName() |
||
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\Goal |
||
86 | */ |
||
87 | View Code Duplication | public function setDescription($description) |
|
96 | |||
97 | /** |
||
98 | * Gets the 'description' parameter. |
||
99 | * |
||
100 | * @return string The Description of the Goal |
||
101 | */ |
||
102 | public function getDescription() |
||
106 | |||
107 | /** |
||
108 | * Sets the 'rule_ids' parameter. |
||
109 | * |
||
110 | * @param array $ruleIds |
||
111 | * |
||
112 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
113 | * |
||
114 | * @return \Acquia\LiftClient\Entity\Goal |
||
115 | */ |
||
116 | View Code Duplication | public function setRuleIds(array $ruleIds) |
|
127 | |||
128 | /** |
||
129 | * Gets the 'rule_ids' parameter. |
||
130 | * |
||
131 | * @return array The Rule Identifiers |
||
132 | */ |
||
133 | public function getRuleIds() |
||
137 | |||
138 | /** |
||
139 | * Sets the 'site_ids' parameter. |
||
140 | * |
||
141 | * @param array $siteIds |
||
142 | * |
||
143 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
144 | * |
||
145 | * @return \Acquia\LiftClient\Entity\Goal |
||
146 | */ |
||
147 | View Code Duplication | public function setSiteIds(array $siteIds) |
|
158 | |||
159 | /** |
||
160 | * Gets the 'site_ids' parameter. |
||
161 | * |
||
162 | * @return array The Site Identifiers |
||
163 | */ |
||
164 | public function getSiteIds() |
||
168 | |||
169 | /** |
||
170 | * Sets the 'event_names' parameter. |
||
171 | * |
||
172 | * @param array $eventNames |
||
173 | * |
||
174 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
175 | * |
||
176 | * @return \Acquia\LiftClient\Entity\Goal |
||
177 | */ |
||
178 | View Code Duplication | public function setEventNames(array $eventNames) |
|
189 | |||
190 | /** |
||
191 | * Gets the 'rule_ids' parameter. |
||
192 | * |
||
193 | * @return array The Rule Identifiers |
||
194 | */ |
||
195 | public function getEventNames() |
||
199 | |||
200 | /** |
||
201 | * Sets the 'global' parameter. |
||
202 | * |
||
203 | * @param bool $global |
||
204 | * |
||
205 | * @return \Acquia\LiftClient\Entity\Slot |
||
206 | */ |
||
207 | public function setGlobal($global) |
||
213 | |||
214 | /** |
||
215 | * Gets the 'global' parameter. |
||
216 | * |
||
217 | * @return bool |
||
218 | */ |
||
219 | public function getGlobal() |
||
223 | |||
224 | /** |
||
225 | * Sets the 'value' parameter. |
||
226 | * |
||
227 | * @param float|int $value |
||
228 | * |
||
229 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
230 | * |
||
231 | * @return \Acquia\LiftClient\Entity\Goal |
||
232 | */ |
||
233 | public function setValue($value) |
||
242 | |||
243 | /** |
||
244 | * Gets the 'value' parameter. |
||
245 | * |
||
246 | * @return float |
||
247 | */ |
||
248 | public function getValue() |
||
252 | } |
||
253 |
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.