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 |
||
17 | class UpdateOrderShippingStatusRequest extends AbstractRequest |
||
18 | { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | private $params = []; |
||
23 | |||
24 | /** |
||
25 | * @param string $sellerId |
||
26 | * @return self |
||
27 | */ |
||
28 | View Code Duplication | public function setSellerId(string $sellerId): self |
|
38 | |||
39 | /** |
||
40 | * @param string $orderId |
||
41 | * @return self |
||
42 | */ |
||
43 | View Code Duplication | public function setOrderId(string $orderId): self |
|
53 | |||
54 | /** |
||
55 | * @param bool $isPointFix |
||
56 | * @return self |
||
57 | */ |
||
58 | View Code Duplication | public function setIsPointFix(bool $isPointFix): self |
|
68 | |||
69 | /** |
||
70 | * @param string $operationUser |
||
71 | * @return self |
||
72 | */ |
||
73 | View Code Duplication | public function setOperationUser(string $operationUser): self |
|
83 | |||
84 | /** |
||
85 | * @param ShipStatus $shipStatus |
||
86 | * @return self |
||
87 | */ |
||
88 | View Code Duplication | public function setShipStatus(ShipStatus $shipStatus): self |
|
98 | |||
99 | /** |
||
100 | * @param ShipMethod $shipMethod |
||
101 | * @return self |
||
102 | */ |
||
103 | View Code Duplication | public function setShipMethod(ShipMethod $shipMethod): self |
|
113 | |||
114 | /** |
||
115 | * @param string $shipNotes |
||
116 | * @return self |
||
117 | */ |
||
118 | View Code Duplication | public function setShipNotes(string $shipNotes): self |
|
132 | |||
133 | /** |
||
134 | * @param string $shipInvoiceNumber1 |
||
135 | * @return self |
||
136 | */ |
||
137 | View Code Duplication | public function setShipInvoiceNumber1(string $shipInvoiceNumber1): self |
|
147 | |||
148 | /** |
||
149 | * @param string $shipInvoiceNumber2 |
||
150 | * @return self |
||
151 | */ |
||
152 | View Code Duplication | public function setShipInvoiceNumber2(string $shipInvoiceNumber2): self |
|
162 | |||
163 | /** |
||
164 | * @param string $shipUrl |
||
165 | * @return self |
||
166 | */ |
||
167 | View Code Duplication | public function setShipUrl(string $shipUrl): self |
|
177 | |||
178 | /** |
||
179 | * @param \DateTimeImmutable $shipDate |
||
180 | * @return self |
||
181 | */ |
||
182 | View Code Duplication | public function setShipDate(\DateTimeImmutable $shipDate): self |
|
194 | |||
195 | /** |
||
196 | * @param \DateTimeImmutable $arrivalDate |
||
197 | * @return self |
||
198 | */ |
||
199 | View Code Duplication | public function setArrivalDate(\DateTimeImmutable $arrivalDate): self |
|
211 | |||
212 | /** |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getParams(): string |
||
224 | |||
225 | /** |
||
226 | * @throws InvalidRequestException |
||
227 | */ |
||
228 | private function validateRequest(): void |
||
246 | } |
||
247 |
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.