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 |
||
32 | class API extends AbstractAPI |
||
33 | { |
||
34 | /** |
||
35 | * Merchant instance. |
||
36 | * |
||
37 | * @var Merchant |
||
38 | */ |
||
39 | protected $merchant; |
||
40 | |||
41 | // api |
||
42 | const API_SEND = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; |
||
43 | const API_QUERY = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo '; |
||
44 | |||
45 | /** |
||
46 | * API constructor. |
||
47 | * |
||
48 | * @param \EasyWeChat\Payment\Merchant $merchant |
||
49 | */ |
||
50 | public function __construct(Merchant $merchant) |
||
54 | |||
55 | /** |
||
56 | * Query MerchantPay. |
||
57 | * |
||
58 | * @param string $mchBillNo |
||
59 | * |
||
60 | * @return \EasyWeChat\Support\Collection |
||
61 | * |
||
62 | * @notice mch_id when query, but mchid when send |
||
63 | */ |
||
64 | public function query($mchBillNo) |
||
74 | |||
75 | /** |
||
76 | * Send MerchantPay. |
||
77 | * |
||
78 | * @param array $params |
||
79 | * @param string $type |
||
|
|||
80 | * |
||
81 | * @return \EasyWeChat\Support\Collection |
||
82 | */ |
||
83 | public function send(array $params) |
||
90 | |||
91 | /** |
||
92 | * Merchant setter. |
||
93 | * |
||
94 | * @param Merchant $merchant |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setMerchant(Merchant $merchant) |
||
102 | |||
103 | /** |
||
104 | * Merchant getter. |
||
105 | * |
||
106 | * @return Merchant |
||
107 | */ |
||
108 | public function getMerchant() |
||
112 | |||
113 | /** |
||
114 | * Make a API request. |
||
115 | * |
||
116 | * @param string $api |
||
117 | * @param array $params |
||
118 | * @param string $method |
||
119 | * |
||
120 | * @return \EasyWeChat\Support\Collection |
||
121 | */ |
||
122 | View Code Duplication | protected function request($api, array $params, $method = 'post') |
|
135 | |||
136 | /** |
||
137 | * Parse Response XML to array. |
||
138 | * |
||
139 | * @param \Psr\Http\Message\ResponseInterface|string $response |
||
140 | * |
||
141 | * @return \EasyWeChat\Support\Collection |
||
142 | */ |
||
143 | protected function parseResponse($response) |
||
151 | } |
||
152 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.