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 |
||
15 | class UpdateOrderStatusRequest extends AbstractRequest |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $params = []; |
||
21 | |||
22 | /** |
||
23 | * @return AbstractApi |
||
24 | */ |
||
25 | public function api() |
||
29 | |||
30 | /** |
||
31 | * @return AbstractResponse |
||
32 | */ |
||
33 | public function response() |
||
37 | |||
38 | /** |
||
39 | * 【必須】ストアアカウント |
||
40 | * |
||
41 | * @param string $sellerId |
||
42 | * @return self |
||
43 | */ |
||
44 | View Code Duplication | public function setSellerId(string $sellerId): self |
|
54 | |||
55 | /** |
||
56 | * 【必須】注文ID |
||
57 | * |
||
58 | * @param string $orderId |
||
59 | * @return self |
||
60 | */ |
||
61 | View Code Duplication | public function setOrderId(string $orderId): self |
|
71 | |||
72 | /** |
||
73 | * 【必須】ポイント確定要否 |
||
74 | * true : ポイント確定します。 |
||
75 | * false : ポイント確定しません。 |
||
76 | * ※注文ステータスを「完了」に変更する際は、必ずポイント確定要否をtrueに指定してください。 |
||
77 | * |
||
78 | * @param bool $isPointFix |
||
79 | * @return self |
||
80 | */ |
||
81 | View Code Duplication | public function setIsPointFix(bool $isPointFix): self |
|
91 | |||
92 | /** |
||
93 | * 【必須】注文ステータス |
||
94 | * |
||
95 | * @param OrderStatus $orderStatus |
||
96 | * @return self |
||
97 | */ |
||
98 | View Code Duplication | public function setOrderStatus(OrderStatus $orderStatus): self |
|
107 | |||
108 | /** |
||
109 | * 更新者名(ビジネスID登録氏名) |
||
110 | * |
||
111 | * @param string $operationUser |
||
112 | * @return self |
||
113 | */ |
||
114 | View Code Duplication | public function setOperationUser(string $operationUser): self |
|
124 | |||
125 | /** |
||
126 | * キャンセル理由 |
||
127 | * |
||
128 | * @param CancelReason $cancelReason |
||
129 | * @return self |
||
130 | */ |
||
131 | View Code Duplication | public function setCancelReason(CancelReason $cancelReason): self |
|
141 | |||
142 | /** |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getParams() |
||
154 | |||
155 | /** |
||
156 | * @throws InvalidRequestException |
||
157 | */ |
||
158 | private function validateRequest(): void |
||
177 | |||
178 | |||
179 | |||
180 | /** |
||
181 | * @return void |
||
182 | */ |
||
183 | protected function validateParams() |
||
186 | } |
||
187 |
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.