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 |
||
6 | View Code Duplication | class AlipayTradeCancelContentBuilder extends ContentBuilder |
|
|
|||
7 | { |
||
8 | // 支付宝交易号,和商户订单号不能同时为空 |
||
9 | private $tradeNo; |
||
10 | |||
11 | // 商户订单号,通过商户订单号撤销相关交易 |
||
12 | private $outTradeNo; |
||
13 | |||
14 | private $bizContentarr = array(); |
||
15 | |||
16 | private $bizContent = null; |
||
17 | |||
18 | public function getBizContent() |
||
25 | |||
26 | public function getOutTradeNo() |
||
30 | |||
31 | public function setOutTradeNo($outTradeNo) |
||
36 | |||
37 | public function getTradeNo() |
||
41 | |||
42 | public function setTradeNo($tradeNo) |
||
47 | |||
48 | |||
49 | } |
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.