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 Alipay implements GatewayInterface |
||
12 | { |
||
13 | use HasHttpRequest; |
||
14 | |||
15 | /** |
||
16 | * 支付宝支付网关. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $gateway = 'https://openapi.alipay.com/gateway.do'; |
||
21 | |||
22 | /** |
||
23 | * 支付宝公共参数. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $config; |
||
28 | |||
29 | /** |
||
30 | * 用户的传参. |
||
31 | * |
||
32 | * @var Yansongda\Pay\Support\Config |
||
33 | */ |
||
34 | protected $user_config; |
||
35 | |||
36 | /** |
||
37 | * [__construct description]. |
||
38 | * |
||
39 | * @author yansongda <[email protected]> |
||
40 | * |
||
41 | * @version 2017-08-14 |
||
42 | * |
||
43 | * @param array $config [description] |
||
44 | */ |
||
45 | public function __construct(array $config) |
||
67 | |||
68 | |||
69 | /** |
||
70 | * 对外接口 - 支付. |
||
71 | * |
||
72 | * @author yansongda <[email protected]> |
||
73 | * |
||
74 | * @version 2017-08-15 |
||
75 | * |
||
76 | * @param array $config_biz [description] |
||
77 | * |
||
78 | * @return string [description] |
||
79 | */ |
||
80 | View Code Duplication | public function pay(array $config_biz = []) |
|
90 | |||
91 | /** |
||
92 | * 对外接口 - 退款. |
||
93 | * |
||
94 | * @author yansongda <[email protected]> |
||
95 | * |
||
96 | * @version 2017-08-15 |
||
97 | * |
||
98 | * @param mixed $config_biz [description] |
||
99 | * |
||
100 | * @return array|boolean [description] |
||
101 | */ |
||
102 | public function refund($config_biz, $refund_amount = null) |
||
113 | |||
114 | /** |
||
115 | * 对外接口 - 关闭. |
||
116 | * |
||
117 | * @author yansongda <[email protected]> |
||
118 | * |
||
119 | * @version 2017-08-15 |
||
120 | * |
||
121 | * @param array|string $config_biz [description] |
||
122 | * |
||
123 | * @return array|boolean [description] |
||
124 | */ |
||
125 | public function close($config_biz) |
||
135 | |||
136 | /** |
||
137 | * 对外接口 - 订单查询 |
||
138 | * @author yansongda <[email protected]> |
||
139 | * |
||
140 | * @version 2017-08-19 |
||
141 | * |
||
142 | * @param string $out_trade_no 商家订单号 |
||
143 | * |
||
144 | * @return array|boolean [description] |
||
145 | */ |
||
146 | public function find($out_trade_no = '') |
||
154 | |||
155 | /** |
||
156 | * 对外接口 - 验证. |
||
157 | * |
||
158 | * @author yansongda <[email protected]> |
||
159 | * |
||
160 | * @version 2017-08-11 |
||
161 | * |
||
162 | * @param array $data 待签名数组 |
||
163 | * @param string $sign 签名字符串-支付宝服务器发送过来的原始串 |
||
164 | * @param bool $sync 是否同步验证 |
||
165 | * |
||
166 | * @return array|boolean [description] |
||
167 | */ |
||
168 | public function verify($data, $sign = null, $sync = false) |
||
184 | |||
185 | /** |
||
186 | * [getMethod description]. |
||
187 | * |
||
188 | * @author yansongda <[email protected]> |
||
189 | * |
||
190 | * @version 2017-08-10 |
||
191 | * |
||
192 | * @return string [description] |
||
193 | */ |
||
194 | abstract protected function getPayMethod(); |
||
195 | |||
196 | /** |
||
197 | * [getProductCode description]. |
||
198 | * |
||
199 | * @author yansongda <[email protected]> |
||
200 | * |
||
201 | * @version 2017-08-10 |
||
202 | * |
||
203 | * @return string [description] |
||
204 | */ |
||
205 | abstract protected function getPayProductCode(); |
||
206 | |||
207 | /** |
||
208 | * [buildHtmlPay description] |
||
209 | * |
||
210 | * @author yansongda <[email protected]> |
||
211 | * |
||
212 | * @version 2017-08-11 |
||
213 | * |
||
214 | * @return string [description] |
||
215 | */ |
||
216 | protected function buildPayHtml() |
||
228 | |||
229 | /** |
||
230 | * get alipay api result. |
||
231 | * |
||
232 | * @author yansongda <[email protected]> |
||
233 | * |
||
234 | * @version 2017-08-12 |
||
235 | * |
||
236 | * @param array $config_biz [description] |
||
237 | * @param string $method [description] |
||
238 | * |
||
239 | * @return array|boolean [description] |
||
240 | */ |
||
241 | protected function getResult($config_biz, $method) |
||
260 | |||
261 | /** |
||
262 | * 签名. |
||
263 | * |
||
264 | * @author yansongda <[email protected]> |
||
265 | * |
||
266 | * @version 2017-08-10 |
||
267 | * |
||
268 | * @return string [description] |
||
269 | */ |
||
270 | protected function getSign() |
||
284 | |||
285 | /** |
||
286 | * 待签名数组. |
||
287 | * |
||
288 | * @author yansongda <[email protected]> |
||
289 | * |
||
290 | * @version 2017-08-11 |
||
291 | * |
||
292 | * @param array $toBeSigned [description] |
||
293 | * @param boolean $verify 是否异步同时验证签名 |
||
294 | * |
||
295 | * @return string [description] |
||
296 | */ |
||
297 | protected function getSignContent(array $toBeSigned, $verify = false) |
||
315 | |||
316 | } |
||
317 |
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..