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 |
||
20 | class UpdateOrderShippingStatusRequest extends AbstractRequest |
||
21 | { |
||
22 | /** |
||
23 | * @return UpdateOrderShippingStatusApi |
||
24 | */ |
||
25 | public function api() |
||
29 | |||
30 | /** |
||
31 | * @return UpdateOrderShippingStatusResponse |
||
32 | */ |
||
33 | public function response() |
||
37 | |||
38 | /** |
||
39 | * @throws InvalidRequestException |
||
40 | */ |
||
41 | protected function validateParams(): void |
||
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getParams() |
||
72 | |||
73 | /** |
||
74 | * @param string $sellerId |
||
75 | * @return self |
||
76 | */ |
||
77 | View Code Duplication | public function setSellerId(string $sellerId): self |
|
87 | |||
88 | /** |
||
89 | * @param string $orderId |
||
90 | * @return self |
||
91 | */ |
||
92 | View Code Duplication | public function setOrderId(string $orderId): self |
|
102 | |||
103 | /** |
||
104 | * @param bool $isPointFix |
||
105 | * @return self |
||
106 | */ |
||
107 | View Code Duplication | public function setIsPointFix(bool $isPointFix): self |
|
117 | |||
118 | /** |
||
119 | * @param string $operationUser |
||
120 | * @return self |
||
121 | */ |
||
122 | View Code Duplication | public function setOperationUser(string $operationUser): self |
|
132 | |||
133 | /** |
||
134 | * @param ShipStatus $shipStatus |
||
135 | * @return self |
||
136 | */ |
||
137 | View Code Duplication | public function setShipStatus(ShipStatus $shipStatus): self |
|
147 | |||
148 | /** |
||
149 | * @param ShipMethod $shipMethod |
||
150 | * @return self |
||
151 | */ |
||
152 | View Code Duplication | public function setShipMethod(ShipMethod $shipMethod): self |
|
162 | |||
163 | /** |
||
164 | * @param string $shipNotes |
||
165 | * @return self |
||
166 | */ |
||
167 | View Code Duplication | public function setShipNotes(string $shipNotes): self |
|
181 | |||
182 | /** |
||
183 | * @param string $shipInvoiceNumber1 |
||
184 | * @return self |
||
185 | */ |
||
186 | View Code Duplication | public function setShipInvoiceNumber1(string $shipInvoiceNumber1): self |
|
196 | |||
197 | /** |
||
198 | * @param string $shipInvoiceNumber2 |
||
199 | * @return self |
||
200 | */ |
||
201 | View Code Duplication | public function setShipInvoiceNumber2(string $shipInvoiceNumber2): self |
|
211 | |||
212 | /** |
||
213 | * @param string $shipUrl |
||
214 | * @return self |
||
215 | */ |
||
216 | View Code Duplication | public function setShipUrl(string $shipUrl): self |
|
226 | |||
227 | /** |
||
228 | * @param \DateTimeImmutable $shipDate |
||
229 | * @return self |
||
230 | */ |
||
231 | View Code Duplication | public function setShipDate(\DateTimeImmutable $shipDate): self |
|
243 | |||
244 | /** |
||
245 | * @param \DateTimeImmutable $arrivalDate |
||
246 | * @return self |
||
247 | */ |
||
248 | View Code Duplication | public function setArrivalDate(\DateTimeImmutable $arrivalDate): self |
|
260 | |||
261 | } |
||
262 |
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.