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 AlipayTradeQueryContentBuilder extends ContentBuilder |
|
|
|||
6 | { |
||
7 | // 支付宝交易号,和商户订单号不能同时为空, 如果同时存在则通过tradeNo查询支付宝交易 |
||
8 | private $tradeNo; |
||
9 | |||
10 | // 商户订单号,通过此商户订单号查询当面付的交易状态 |
||
11 | private $outTradeNo; |
||
12 | |||
13 | private $bizContentarr = array(); |
||
14 | |||
15 | private $bizContent = null; |
||
16 | |||
17 | public function getBizContent() |
||
24 | |||
25 | public function getOutTradeNo() |
||
29 | |||
30 | public function setOutTradeNo($outTradeNo) |
||
35 | |||
36 | public function getTradeNo() |
||
40 | |||
41 | public function setTradeNo($tradeNo) |
||
46 | |||
47 | |||
48 | } |
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.