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 |
||
16 | View Code Duplication | class ShippingAttribute extends Base |
|
|
|||
17 | { |
||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | protected $id; |
||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | protected $customerShippingId; |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $text1; |
||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $text2; |
||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $text3; |
||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $text4; |
||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $text5; |
||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $text6; |
||
50 | |||
51 | /** |
||
52 | * @return int |
||
53 | */ |
||
54 | public function getId() |
||
58 | |||
59 | /** |
||
60 | * @param int $id |
||
61 | * |
||
62 | * @return ShippingAttribute |
||
63 | */ |
||
64 | public function setId($id) |
||
70 | |||
71 | /** |
||
72 | * @return int |
||
73 | */ |
||
74 | public function getCustomerShippingId() |
||
78 | |||
79 | /** |
||
80 | * @param int $customerShippingId |
||
81 | * |
||
82 | * @return ShippingAttribute |
||
83 | */ |
||
84 | public function setCustomerShippingId($customerShippingId) |
||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | public function getText1() |
||
98 | |||
99 | /** |
||
100 | * @param string $text1 |
||
101 | * |
||
102 | * @return ShippingAttribute |
||
103 | */ |
||
104 | public function setText1($text1) |
||
110 | |||
111 | /** |
||
112 | * @return string |
||
113 | */ |
||
114 | public function getText2() |
||
118 | |||
119 | /** |
||
120 | * @param string $text2 |
||
121 | * |
||
122 | * @return ShippingAttribute |
||
123 | */ |
||
124 | public function setText2($text2) |
||
130 | |||
131 | /** |
||
132 | * @return string |
||
133 | */ |
||
134 | public function getText3() |
||
138 | |||
139 | /** |
||
140 | * @param string $text3 |
||
141 | * |
||
142 | * @return ShippingAttribute |
||
143 | */ |
||
144 | public function setText3($text3) |
||
150 | |||
151 | /** |
||
152 | * @return string |
||
153 | */ |
||
154 | public function getText4() |
||
158 | |||
159 | /** |
||
160 | * @param string $text4 |
||
161 | * |
||
162 | * @return ShippingAttribute |
||
163 | */ |
||
164 | public function setText4($text4) |
||
170 | |||
171 | /** |
||
172 | * @return string |
||
173 | */ |
||
174 | public function getText5() |
||
178 | |||
179 | /** |
||
180 | * @param string $text5 |
||
181 | * |
||
182 | * @return ShippingAttribute |
||
183 | */ |
||
184 | public function setText5($text5) |
||
190 | |||
191 | /** |
||
192 | * @return string |
||
193 | */ |
||
194 | public function getText6() |
||
198 | |||
199 | /** |
||
200 | * @param string $text6 |
||
201 | * |
||
202 | * @return ShippingAttribute |
||
203 | */ |
||
204 | public function setText6($text6) |
||
210 | } |
||
211 |
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.