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 |
||
11 | View Code Duplication | class OrderedItem extends AbstractModel |
|
|
|||
12 | { |
||
13 | /** |
||
14 | * @return mixed |
||
15 | */ |
||
16 | 1 | public function getOrderId() |
|
20 | |||
21 | /** |
||
22 | * @param string $orderId |
||
23 | */ |
||
24 | 1 | public function setOrderId($orderId) |
|
28 | |||
29 | /** |
||
30 | * @return mixed |
||
31 | */ |
||
32 | 1 | public function getOrderItemId() |
|
36 | |||
37 | /** |
||
38 | * @param string $orderItemId |
||
39 | */ |
||
40 | 1 | public function setOrderItemId($orderItemId) |
|
44 | |||
45 | /** |
||
46 | * @return mixed |
||
47 | */ |
||
48 | 1 | public function getProductId() |
|
52 | |||
53 | /** |
||
54 | * @param string $productId |
||
55 | */ |
||
56 | 1 | public function setProductId($productId) |
|
60 | |||
61 | /** |
||
62 | * @return mixed |
||
63 | */ |
||
64 | 1 | public function getEan() |
|
68 | |||
69 | /** |
||
70 | * @param string $ean |
||
71 | */ |
||
72 | 1 | public function setEan($ean) |
|
76 | |||
77 | /** |
||
78 | * @return mixed |
||
79 | */ |
||
80 | 1 | public function getAmount() |
|
84 | |||
85 | /** |
||
86 | * @param string $amount |
||
87 | */ |
||
88 | 1 | public function setAmount($amount) |
|
92 | |||
93 | /** |
||
94 | * @return mixed |
||
95 | */ |
||
96 | 1 | public function getStockbaseGuid() |
|
100 | |||
101 | /** |
||
102 | * @param string $stockbaseGuid |
||
103 | */ |
||
104 | 1 | public function setStockbaseGuid($stockbaseGuid) |
|
108 | |||
109 | /** |
||
110 | * @return mixed |
||
111 | */ |
||
112 | 1 | public function getCreatedAt() |
|
116 | |||
117 | /** |
||
118 | * @param string $createdAt |
||
119 | */ |
||
120 | 1 | public function setCreatedAt($createdAt) |
|
124 | |||
125 | 7 | protected function _construct() |
|
129 | } |
||
130 |
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.