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 |
||
7 | View Code Duplication | class Settlement extends ResultObject |
|
|
|||
8 | { |
||
9 | /** @type string ID of the settlement. |
||
10 | Value assigned by Cardinity. */ |
||
11 | private $id; |
||
12 | |||
13 | /** @type float Amount settled shown in #0.00 format. */ |
||
14 | private $amount; |
||
15 | |||
16 | /** @type string Three-letter ISO currency code representing the currency in |
||
17 | which the settlement was made. |
||
18 | Supported currencies: EUR, USD. |
||
19 | Value assigned by Cardinity. */ |
||
20 | private $currency; |
||
21 | |||
22 | /** @type string Can only be: settlement. |
||
23 | Value assigned by Cardinity. */ |
||
24 | private $type; |
||
25 | |||
26 | /** @type string Settlement creation time as defined in RFC 3339 Section 5.6. |
||
27 | UTC timezone. |
||
28 | Value assigned by Cardinity. */ |
||
29 | private $created; |
||
30 | |||
31 | /** @type boolean Indicates whether a settlement was made in live or testing |
||
32 | mode. |
||
33 | Value assigned by Cardinity. */ |
||
34 | private $live; |
||
35 | |||
36 | /** @type string ID of the settled payment. |
||
37 | Value assigned by Cardinity. */ |
||
38 | private $parentId; |
||
39 | |||
40 | /** @type string Settlement status. |
||
41 | Can be one of the following: approved, declined. |
||
42 | Value assigned by Cardinity. */ |
||
43 | private $status; |
||
44 | |||
45 | /** @type string Error message. |
||
46 | Returned only if status is declined. |
||
47 | Provides human readable information why the settlement failed. |
||
48 | Value assigned by Cardinity. */ |
||
49 | private $error; |
||
50 | |||
51 | /** @type string Optional. Order ID provided by a merchant in initial |
||
52 | payment. Must be between 2 and 50 characters [A-Za-z0-9'.-]. |
||
53 | Value assigned by Cardinity. */ |
||
54 | private $orderId; |
||
55 | |||
56 | /** @type string Settlement description provided by a merchant. |
||
57 | Maximum length 255 characters. */ |
||
58 | private $description; |
||
59 | |||
60 | /** |
||
61 | * Gets the value of id. |
||
62 | * @return mixed |
||
63 | */ |
||
64 | public function getId() |
||
68 | |||
69 | /** |
||
70 | * Sets the value of id. |
||
71 | * @param mixed $id the id |
||
72 | * @return void |
||
73 | */ |
||
74 | public function setId($id) |
||
78 | |||
79 | /** |
||
80 | * Gets the value of amount. |
||
81 | * @return mixed |
||
82 | */ |
||
83 | public function getAmount() |
||
87 | |||
88 | /** |
||
89 | * Sets the value of amount. |
||
90 | * @param mixed $amount the amount |
||
91 | * @return void |
||
92 | */ |
||
93 | public function setAmount($amount) |
||
97 | |||
98 | /** |
||
99 | * Gets the value of currency. |
||
100 | * @return mixed |
||
101 | */ |
||
102 | public function getCurrency() |
||
106 | |||
107 | /** |
||
108 | * Sets the value of currency. |
||
109 | * @param mixed $currency the currency |
||
110 | * @return void |
||
111 | */ |
||
112 | public function setCurrency($currency) |
||
116 | |||
117 | /** |
||
118 | * Gets the value of type. |
||
119 | * @return mixed |
||
120 | */ |
||
121 | public function getType() |
||
125 | |||
126 | /** |
||
127 | * Sets the value of type. |
||
128 | * @param mixed $type the type |
||
129 | * @return void |
||
130 | */ |
||
131 | public function setType($type) |
||
135 | |||
136 | /** |
||
137 | * Gets the value of created. |
||
138 | * @return mixed |
||
139 | */ |
||
140 | public function getCreated() |
||
144 | |||
145 | /** |
||
146 | * Sets the value of created. |
||
147 | * @param mixed $created the created |
||
148 | * @return void |
||
149 | */ |
||
150 | public function setCreated($created) |
||
154 | |||
155 | /** |
||
156 | * Gets the value of live. |
||
157 | * @return mixed |
||
158 | */ |
||
159 | public function getLive() |
||
163 | |||
164 | /** |
||
165 | * Sets the value of live. |
||
166 | * @param mixed $live the live |
||
167 | * @return void |
||
168 | */ |
||
169 | public function setLive($live) |
||
173 | |||
174 | /** |
||
175 | * Gets the value of parentId. |
||
176 | * @return mixed |
||
177 | */ |
||
178 | public function getParentId() |
||
182 | |||
183 | /** |
||
184 | * Sets the value of parentId. |
||
185 | * @param mixed $parentId the parent id |
||
186 | * @return void |
||
187 | */ |
||
188 | public function setParentId($parentId) |
||
192 | |||
193 | /** |
||
194 | * Gets the value of status. |
||
195 | * @return mixed |
||
196 | */ |
||
197 | public function getStatus() |
||
201 | |||
202 | /** |
||
203 | * Sets the value of status. |
||
204 | * @param mixed $status the status |
||
205 | * @return void |
||
206 | */ |
||
207 | public function setStatus($status) |
||
211 | |||
212 | /** |
||
213 | * Gets the value of error. |
||
214 | * @return mixed |
||
215 | */ |
||
216 | public function getError() |
||
220 | |||
221 | /** |
||
222 | * Sets the value of error. |
||
223 | * @param mixed $error the error |
||
224 | * @return void |
||
225 | */ |
||
226 | public function setError($error) |
||
230 | |||
231 | /** |
||
232 | * Gets the value of orderId. |
||
233 | * @return mixed |
||
234 | */ |
||
235 | public function getOrderId() |
||
239 | |||
240 | /** |
||
241 | * Sets the value of orderId. |
||
242 | * @param mixed $orderId the order id |
||
243 | * @return void |
||
244 | */ |
||
245 | public function setOrderId($orderId) |
||
249 | |||
250 | /** |
||
251 | * Gets the value of description. |
||
252 | * @return mixed |
||
253 | */ |
||
254 | public function getDescription() |
||
258 | |||
259 | /** |
||
260 | * Sets the value of description. |
||
261 | * @param mixed $description the description |
||
262 | * @return void |
||
263 | */ |
||
264 | public function setDescription($description) |
||
268 | |||
269 | /** |
||
270 | * Check if settlement is approved |
||
271 | * @return boolean |
||
272 | */ |
||
273 | public function isApproved() |
||
277 | |||
278 | /** |
||
279 | * Check if settlement is declined |
||
280 | * @return boolean |
||
281 | */ |
||
282 | public function isDeclined() |
||
286 | } |
||
287 |
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.