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 |
||
14 | class UpdateOrderInfoRequest extends AbstractRequest |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @return UpdateOrderInfoApi |
||
19 | */ |
||
20 | public function api() |
||
24 | |||
25 | /** |
||
26 | * @return UpdateOrderInfoResponse |
||
27 | */ |
||
28 | public function response() |
||
32 | |||
33 | /** |
||
34 | * @return void |
||
35 | */ |
||
36 | protected function validateParams() |
||
39 | |||
40 | /** |
||
41 | * @return string |
||
42 | */ |
||
43 | public function getParams() |
||
53 | |||
54 | /** |
||
55 | * 閲覧済みフラグ |
||
56 | * 更新する時必ずtrue |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function setIsSeen(): self |
||
65 | |||
66 | /** |
||
67 | * 悪戯フラグ |
||
68 | * |
||
69 | * @param SuspectFlag $suspectFlag |
||
70 | * @return UpdateOrderInfoRequest |
||
71 | */ |
||
72 | View Code Duplication | public function setSuspect(SuspectFlag $suspectFlag): self |
|
82 | |||
83 | /** |
||
84 | * 支払い分類 |
||
85 | * |
||
86 | * @param PayType $payType |
||
87 | * @return UpdateOrderInfoRequest |
||
88 | */ |
||
89 | View Code Duplication | public function setPayType(PayType $payType): self |
|
99 | } |
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.