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 |
||
13 | class UpdateOrderStatusRequest extends AbstractRequest |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @return UpdateOrderStatusApi |
||
18 | */ |
||
19 | public function api() |
||
23 | |||
24 | /** |
||
25 | * @return UpdateOrderStatusResponse |
||
26 | */ |
||
27 | public function response() |
||
31 | |||
32 | /** |
||
33 | * @return void |
||
34 | */ |
||
35 | protected function validateParams(): void |
||
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getParams() |
||
67 | |||
68 | /** |
||
69 | * 【必須】ストアアカウント |
||
70 | * |
||
71 | * @param string $sellerId |
||
72 | * @return self |
||
73 | */ |
||
74 | View Code Duplication | public function setSellerId(string $sellerId): self |
|
84 | |||
85 | /** |
||
86 | * 【必須】注文ID |
||
87 | * |
||
88 | * @param string $orderId |
||
89 | * @return self |
||
90 | */ |
||
91 | public function setOrderId(string $orderId): self |
||
101 | |||
102 | /** |
||
103 | * 【必須】ポイント確定要否 |
||
104 | * true : ポイント確定します。 |
||
105 | * false : ポイント確定しません。 |
||
106 | * ※注文ステータスを「完了」に変更する際は、必ずポイント確定要否をtrueに指定してください。 |
||
107 | * |
||
108 | * @param bool $isPointFix |
||
109 | * @return self |
||
110 | */ |
||
111 | public function setIsPointFix(bool $isPointFix): self |
||
121 | |||
122 | /** |
||
123 | * 【必須】注文ステータス |
||
124 | * |
||
125 | * @param OrderStatus $orderStatus |
||
126 | * @return self |
||
127 | */ |
||
128 | public function setOrderStatus(OrderStatus $orderStatus): self |
||
137 | |||
138 | /** |
||
139 | * 更新者名(ビジネスID登録氏名) |
||
140 | * |
||
141 | * @param string $operationUser |
||
142 | * @return self |
||
143 | */ |
||
144 | public function setOperationUser(string $operationUser): self |
||
154 | |||
155 | /** |
||
156 | * キャンセル理由 |
||
157 | * |
||
158 | * @param CancelReason $cancelReason |
||
159 | * @return self |
||
160 | */ |
||
161 | public function setCancelReason(CancelReason $cancelReason): self |
||
171 | |||
172 | } |
||
173 |
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.