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 |
||
| 11 | abstract class Wechat implements GatewayInterface |
||
| 12 | { |
||
| 13 | use HasHttpRequest; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | protected $endpoint = 'https://api.mch.weixin.qq.com/'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $gateway_order = 'pay/unifiedorder'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $gateway_query = 'pay/orderquery'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $gateway_close = 'pay/closeorder'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | protected $gateway_refund = 'secapi/pay/refund'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | protected $config; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var \Yansongda\Pay\Support\Config |
||
| 47 | */ |
||
| 48 | protected $user_config; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * [__construct description]. |
||
| 52 | * |
||
| 53 | * @author yansongda <[email protected]> |
||
| 54 | * |
||
| 55 | * @param array $config |
||
| 56 | */ |
||
| 57 | public function __construct(array $config) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * pay a order. |
||
| 77 | * |
||
| 78 | * @author yansongda <[email protected]> |
||
| 79 | * |
||
| 80 | * @param array $config_biz |
||
| 81 | * |
||
| 82 | * @return mixed |
||
| 83 | */ |
||
| 84 | abstract public function pay(array $config_biz = []); |
||
| 85 | |||
| 86 | /** |
||
| 87 | * refund. |
||
| 88 | * |
||
| 89 | * @author yansongda <[email protected]> |
||
| 90 | * |
||
| 91 | * @return string|bool |
||
| 92 | */ |
||
| 93 | public function refund($config_biz = []) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * close a order. |
||
| 105 | * |
||
| 106 | * @author yansongda <[email protected]> |
||
| 107 | * |
||
| 108 | * @return array|bool |
||
| 109 | */ |
||
| 110 | public function close($out_trade_no = '') |
||
| 118 | |||
| 119 | /** |
||
| 120 | * find a order. |
||
| 121 | * |
||
| 122 | * @author yansongda <[email protected]> |
||
| 123 | * |
||
| 124 | * @param string $out_trade_no |
||
| 125 | * |
||
| 126 | * @return array|bool |
||
| 127 | */ |
||
| 128 | public function find($out_trade_no = '') |
||
| 136 | |||
| 137 | /** |
||
| 138 | * verify the notify. |
||
| 139 | * |
||
| 140 | * @author yansongda <[email protected]> |
||
| 141 | * |
||
| 142 | * @param string $data |
||
| 143 | * @param string $sign |
||
| 144 | * @param bool $sync |
||
| 145 | * |
||
| 146 | * @return array|bool |
||
| 147 | */ |
||
| 148 | public function verify($data, $sign = null, $sync = false) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * get trade type config. |
||
| 159 | * |
||
| 160 | * @author yansongda <[email protected]> |
||
| 161 | * |
||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | abstract protected function getTradeType(); |
||
| 165 | |||
| 166 | /** |
||
| 167 | * pre order. |
||
| 168 | * |
||
| 169 | * @author yansongda <[email protected]> |
||
| 170 | * |
||
| 171 | * @param array $config_biz |
||
| 172 | * |
||
| 173 | * @return array |
||
| 174 | */ |
||
| 175 | protected function preOrder($config_biz = []) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * get api result. |
||
| 184 | * |
||
| 185 | * @author yansongda <[email protected]> |
||
| 186 | * |
||
| 187 | * @param string $path |
||
| 188 | * @param bool $cert |
||
| 189 | * |
||
| 190 | * @return array |
||
| 191 | */ |
||
| 192 | protected function getResult($path, $cert = false) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * sign. |
||
| 230 | * |
||
| 231 | * @author yansongda <[email protected]> |
||
| 232 | * |
||
| 233 | * @param array $data |
||
| 234 | * |
||
| 235 | * @return string |
||
| 236 | */ |
||
| 237 | protected function getSign($data) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * get sign content. |
||
| 252 | * |
||
| 253 | * @author yansongda <[email protected]> |
||
| 254 | * |
||
| 255 | * @param array $data |
||
| 256 | * |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | protected function getSignContent($data) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * create random string. |
||
| 272 | * |
||
| 273 | * @author yansongda <[email protected]> |
||
| 274 | * |
||
| 275 | * @param int $length |
||
| 276 | * |
||
| 277 | * @return string |
||
| 278 | */ |
||
| 279 | protected function createNonceStr($length = 16) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * convert to xml. |
||
| 293 | * |
||
| 294 | * @author yansongda <[email protected]> |
||
| 295 | * |
||
| 296 | * @param array $data |
||
| 297 | * |
||
| 298 | * @return string |
||
| 299 | */ |
||
| 300 | protected function toXml($data) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * convert to array. |
||
| 318 | * |
||
| 319 | * @author yansongda <[email protected]> |
||
| 320 | * |
||
| 321 | * @param string $xml |
||
| 322 | * |
||
| 323 | * @return array |
||
| 324 | */ |
||
| 325 | protected function fromXml($xml) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * delete trade_type and notify_url. |
||
| 338 | * |
||
| 339 | * @author yansongda <[email protected]> |
||
| 340 | * |
||
| 341 | * @return bool |
||
| 342 | */ |
||
| 343 | protected function unsetTradeTypeAndNotifyUrl() |
||
| 350 | } |
||
| 351 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: