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 |
||
5 | View Code Duplication | class AlipayTradeRefundQueryRequest |
|
|
|||
6 | { |
||
7 | /** |
||
8 | * 统一收单交易退款查询 |
||
9 | **/ |
||
10 | private $bizContent; |
||
11 | |||
12 | private $apiParas = array(); |
||
13 | private $terminalType; |
||
14 | private $terminalInfo; |
||
15 | private $prodCode; |
||
16 | private $apiVersion="1.0"; |
||
17 | private $notifyUrl; |
||
18 | private $returnUrl; |
||
19 | private $needEncrypt=false; |
||
20 | |||
21 | |||
22 | public function setBizContent($bizContent) |
||
27 | |||
28 | public function getBizContent() |
||
32 | |||
33 | public function getApiMethodName() |
||
37 | |||
38 | public function setNotifyUrl($notifyUrl) |
||
42 | |||
43 | public function getNotifyUrl() |
||
47 | |||
48 | public function setReturnUrl($returnUrl) |
||
52 | |||
53 | public function getReturnUrl() |
||
57 | |||
58 | public function getApiParas() |
||
62 | |||
63 | public function getTerminalType() |
||
67 | |||
68 | public function setTerminalType($terminalType) |
||
72 | |||
73 | public function getTerminalInfo() |
||
77 | |||
78 | public function setTerminalInfo($terminalInfo) |
||
82 | |||
83 | public function getProdCode() |
||
87 | |||
88 | public function setProdCode($prodCode) |
||
92 | |||
93 | public function setApiVersion($apiVersion) |
||
97 | |||
98 | public function getApiVersion() |
||
102 | |||
103 | public function setNeedEncrypt($needEncrypt) |
||
109 | |||
110 | public function getNeedEncrypt() |
||
114 | |||
115 | } |
||
116 |
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.