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 | abstract class Wechat implements GatewayInterface |
||
| 15 | { |
||
| 16 | use HasHttpRequest; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * 支付订单. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $gateway = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * 查询订单. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $gateway_query = 'https://api.mch.weixin.qq.com/pay/orderquery'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * 关闭订单. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $gateway_close = 'https://api.mch.weixin.qq.com/pay/closeorder'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * 退款. |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | protected $gateway_refund = 'https://api.mch.weixin.qq.com/secapi/pay/refund'; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * 配置项. |
||
| 48 | * |
||
| 49 | * @var array |
||
| 50 | */ |
||
| 51 | protected $config; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * 用户传参配置项. |
||
| 55 | * |
||
| 56 | * @var Yansongda\Pay\Support\Config |
||
| 57 | */ |
||
| 58 | protected $user_config; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * [__construct description]. |
||
| 62 | * |
||
| 63 | * @author yansongda <[email protected]> |
||
| 64 | * |
||
| 65 | * @version 2017-08-14 |
||
| 66 | * |
||
| 67 | * @param array $config [description] |
||
| 68 | */ |
||
| 69 | public function __construct(array $config) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * 对外支付接口. |
||
| 85 | * |
||
| 86 | * @author yansongda <[email protected]> |
||
| 87 | * |
||
| 88 | * @version 2017-08-15 |
||
| 89 | * |
||
| 90 | * @param array $config_biz [description] |
||
| 91 | * |
||
| 92 | * @return mixed [description] |
||
| 93 | */ |
||
| 94 | abstract public function pay(array $config_biz = []); |
||
| 95 | |||
| 96 | /** |
||
| 97 | * 对外接口 - 退款. |
||
| 98 | * |
||
| 99 | * @author yansongda <[email protected]> |
||
| 100 | * |
||
| 101 | * @version 2017-08-15 |
||
| 102 | * |
||
| 103 | * @return [type] [description] |
||
| 104 | */ |
||
| 105 | public function refund(array $config_biz = []) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * 对外接口 - 关闭订单. |
||
| 117 | * |
||
| 118 | * @author yansongda <[email protected]> |
||
| 119 | * |
||
| 120 | * @version 2017-08-15 |
||
| 121 | * |
||
| 122 | * @return array|boolean [description] |
||
| 123 | */ |
||
| 124 | View Code Duplication | public function close($out_trade_no = '') |
|
| 132 | |||
| 133 | /** |
||
| 134 | * 对外接口 - 订单查询 |
||
| 135 | * @author yansongda <[email protected]> |
||
| 136 | * |
||
| 137 | * @version 2017-08-19 |
||
| 138 | * |
||
| 139 | * @param string $out_trade_no 商家订单号 |
||
| 140 | * |
||
| 141 | * @return array|boolean [description] |
||
| 142 | */ |
||
| 143 | View Code Duplication | public function find($out_trade_no = '') |
|
| 152 | |||
| 153 | /** |
||
| 154 | * 验证签名. |
||
| 155 | * |
||
| 156 | * @author yansongda <[email protected]> |
||
| 157 | * |
||
| 158 | * @version 2017-08-15 |
||
| 159 | * |
||
| 160 | * @param string $data 待验证 xml 数据 |
||
| 161 | * @param string $sign 服务器返回的签名 |
||
| 162 | * @param bool $sync is sync sign |
||
| 163 | * |
||
| 164 | * @return array|boolean 是否相符 |
||
| 165 | */ |
||
| 166 | public function verify($data, $sign = null, $sync = false) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * 获取交易类型. |
||
| 177 | * @author yansongda <[email protected]> |
||
| 178 | * |
||
| 179 | * @version 2017-08-17 |
||
| 180 | * |
||
| 181 | * @return string [description] |
||
| 182 | */ |
||
| 183 | abstract protected function getTradeType(); |
||
| 184 | |||
| 185 | /** |
||
| 186 | * 预下单. |
||
| 187 | * |
||
| 188 | * @author yansongda <[email protected]> |
||
| 189 | * |
||
| 190 | * @version 2017-08-15 |
||
| 191 | * |
||
| 192 | * @param array $config_biz 业务参数 |
||
| 193 | * |
||
| 194 | * @return array 服务器返回结果数组 |
||
| 195 | */ |
||
| 196 | protected function preOrder($config_biz = []) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * 获取 API 结果. |
||
| 206 | * |
||
| 207 | * @author yansongda <[email protected]> |
||
| 208 | * |
||
| 209 | * @version 2017-08-19 |
||
| 210 | * |
||
| 211 | * @param string $end_point [description] |
||
| 212 | * @param bool $cert 是否使用证书 |
||
| 213 | * |
||
| 214 | * @return [type] [description] |
||
| 215 | */ |
||
| 216 | protected function getResult($end_point, $cert = false) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * 签名. |
||
| 247 | * |
||
| 248 | * @author yansongda <[email protected]> |
||
| 249 | * |
||
| 250 | * @version 2017-08-15 |
||
| 251 | * |
||
| 252 | * @param array $data 带签名数组 |
||
| 253 | * |
||
| 254 | * @return string [description] |
||
| 255 | */ |
||
| 256 | protected function getSign($data) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * 将数组转换成 URL 格式. |
||
| 271 | * |
||
| 272 | * @author yansongda <[email protected]> |
||
| 273 | * |
||
| 274 | * @version 2017-08-15 |
||
| 275 | * |
||
| 276 | * @param array $data [description] |
||
| 277 | * |
||
| 278 | * @return string [description] |
||
| 279 | */ |
||
| 280 | protected function getSignContent($data) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * 生成随机字符串. |
||
| 296 | * |
||
| 297 | * @author yansongda <[email protected]> |
||
| 298 | * |
||
| 299 | * @version 2017-08-14 |
||
| 300 | * |
||
| 301 | * @param integer $length [description] |
||
| 302 | * |
||
| 303 | * @return string [description] |
||
| 304 | */ |
||
| 305 | protected function createNonceStr($length = 16) { |
||
| 315 | |||
| 316 | /** |
||
| 317 | * 转化为 xml. |
||
| 318 | * |
||
| 319 | * @author yansongda <[email protected]> |
||
| 320 | * |
||
| 321 | * @version 2017-08-14 |
||
| 322 | * |
||
| 323 | * @param array $data 带转化数组 |
||
| 324 | * |
||
| 325 | * @return string 转化后的xml字符串 |
||
| 326 | */ |
||
| 327 | protected function toXml($data) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * xml 转化为 array. |
||
| 348 | * |
||
| 349 | * @author yansongda <[email protected]> |
||
| 350 | * |
||
| 351 | * @version 2017-08-14 |
||
| 352 | * |
||
| 353 | * @param string $xml xml字符串 |
||
| 354 | * |
||
| 355 | * @return array 转化后的数组 |
||
| 356 | */ |
||
| 357 | protected function fromXml($xml) |
||
| 367 | } |
||
| 368 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..