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 | class UpdateOrderShippingStatusRequest extends AbstractRequest |
||
12 | { |
||
13 | private $params = []; |
||
14 | |||
15 | public function __construct() |
||
18 | |||
19 | /** |
||
20 | * @param string $sellerId |
||
21 | * @return self |
||
22 | */ |
||
23 | View Code Duplication | public function setSellerId(string $sellerId): self |
|
33 | |||
34 | /** |
||
35 | * @param string $orderId |
||
36 | * @return self |
||
37 | */ |
||
38 | View Code Duplication | public function setOrderId(string $orderId): self |
|
48 | |||
49 | /** |
||
50 | * @param bool $isPointFix |
||
51 | * @return self |
||
52 | */ |
||
53 | View Code Duplication | public function setIsPointFix(bool $isPointFix): self |
|
63 | |||
64 | /** |
||
65 | * @param string $operationUser |
||
66 | * @return self |
||
67 | */ |
||
68 | View Code Duplication | public function setOperationUser(string $operationUser): self |
|
78 | |||
79 | /** |
||
80 | * @param ShipStatus $shipStatus |
||
81 | * @return self |
||
82 | */ |
||
83 | public function setShipStatus(ShipStatus $shipStatus): self |
||
93 | |||
94 | /** |
||
95 | * @param string $shipMethod |
||
96 | * @return self |
||
97 | */ |
||
98 | public function setShipMethod(string $shipMethod): self |
||
114 | |||
115 | /** |
||
116 | * @param string $shipNotes |
||
117 | * @return self |
||
118 | */ |
||
119 | View Code Duplication | public function setShipNotes(string $shipNotes): self |
|
133 | |||
134 | /** |
||
135 | * @param string $shipInvoiceNumber1 |
||
136 | * @return self |
||
137 | */ |
||
138 | View Code Duplication | public function setShipInvoiceNumber1(string $shipInvoiceNumber1): self |
|
148 | |||
149 | /** |
||
150 | * @param string $shipInvoiceNumber2 |
||
151 | * @return self |
||
152 | */ |
||
153 | View Code Duplication | public function setShipInvoiceNumber2(string $shipInvoiceNumber2): self |
|
163 | |||
164 | /** |
||
165 | * @param string $shipUrl |
||
166 | * @return self |
||
167 | */ |
||
168 | View Code Duplication | public function setShipUrl(string $shipUrl): self |
|
178 | |||
179 | /** |
||
180 | * @param \DateTimeImmutable $shipDate |
||
181 | * @return self |
||
182 | */ |
||
183 | View Code Duplication | public function setShipDate(\DateTimeImmutable $shipDate): self |
|
195 | |||
196 | /** |
||
197 | * @param \DateTimeImmutable $arrivalDate |
||
198 | * @return self |
||
199 | */ |
||
200 | View Code Duplication | public function setArrivalDate(\DateTimeImmutable $arrivalDate): self |
|
212 | |||
213 | /** |
||
214 | * getParams |
||
215 | * @return array |
||
216 | */ |
||
217 | public function getParams(): array |
||
223 | |||
224 | /** |
||
225 | * @throws InvalidRequestException |
||
226 | */ |
||
227 | private function validateRequest(): void |
||
245 | } |
||
246 |
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.