Coupon   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
c 1
b 0
f 0
dl 0
loc 53
ccs 20
cts 20
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A queryCouponsInfo() 0 7 3
A sendCoupon() 0 8 3
A queryCouponStock() 0 5 1
1
<?php
2
namespace zhangv\wechat\pay\service;
3
use \zhangv\wechat\pay\WechatPay;
4
use \Exception;
5
6
/**
7
 * 代金券
8
 * @license MIT
9
 * @zhangv
10
 * @link https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_1
11
 *
12
 */
13
class Coupon extends WechatPay {
14
15
	/**
16
	 * 发放代金券
17
	 * @param $coupon_stock_id
18
	 * @param $open_id
19
	 * @param $partner_trade_no
20
	 * @param string $op_user_id
21
	 * @param array $ext
22
	 * @return array
23
	 * @throws Exception
24
	 */
25 2
	public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = array()){
26 2
		$data = (!empty($ext) && is_array($ext))?$ext:array();
27 2
		$data["partner_trade_no"] = $partner_trade_no;
28 2
		$data["coupon_stock_id"] = $coupon_stock_id;
29 2
		$data["openid_count"] = 1;
30 2
		$data["open_id"] = $open_id;
31 2
		$data["op_user_id"] = $op_user_id;
32 2
		return $this->post(self::URL_SEND_COUPON,$data,true);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->post(self:...ND_COUPON, $data, true) also could return the type string|true which is incompatible with the documented return type array.
Loading history...
33
	}
34
35
	/**
36
	 * 查询代金券批次
37
	 * @param $coupon_stock_id
38
	 * @param string $op_user_id
39
	 * @return array
40
	 * @throws Exception
41
	 */
42 1
	public function queryCouponStock($coupon_stock_id,$op_user_id = ''){
43 1
		$data = array();
44 1
		$data["coupon_stock_id"] = $coupon_stock_id;
45 1
		$data["op_user_id"] = $op_user_id;
46 1
		return $this->post(self::URL_QUERY_COUPON_STOCK,$data,false);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->post(self:...ON_STOCK, $data, false) also could return the type string|true which is incompatible with the documented return type array.
Loading history...
47
	}
48
49
	/**
50
	 * 查询代金券信息
51
	 * @param $coupon_id
52
	 * @param $open_id
53
	 * @param $stock_id
54
	 * @param string $op_user_id
55
	 * @param array $ext
56
	 * @return array
57
	 * @throws Exception
58
	 */
59 1
	public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = array()){
60 1
		$data = (!empty($ext) && is_array($ext))?$ext:array();
61 1
		$data["coupon_id"] = $coupon_id;
62 1
		$data["stock_id"] = $stock_id;
63 1
		$data["open_id"] = $open_id;
64 1
		$data["op_user_id"] = $op_user_id;
65 1
		return $this->post(self::URL_QUERY_COUPON_INFO,$data,false);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->post(self:...PON_INFO, $data, false) also could return the type string|true which is incompatible with the documented return type array.
Loading history...
66
	}
67
68
}