QRCode::fromArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/*
3
 * This file is part of the slince/youzan-pay package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Slince\YouzanPay\Api;
12
13
use Slince\YouzanPay\Amount;
14
15
/**
16
 *  WAIT_BUYER_PAY = "WAIT_BUYER_PAY",.
17
    // 待确认,包括(待成团:拼团订单、待接单:外卖订单)
18
    WAIT_CONFIRM = "WAIT_CONFIRM",
19
    // 等待卖家发货,即:买家已付款
20
    WAIT_SELLER_SEND_GOODS = "WAIT_SELLER_SEND_GOODS",
21
    // 等待买家确认收货,即:卖家已发货
22
    WAIT_BUYER_CONFIRM_GOODS = "WAIT_BUYER_CONFIRM_GOODS",
23
    // 买家已签收
24
    TRADE_BUYER_SIGNED = "TRADE_BUYER_SIGNED",
25
    // 交易成功
26
    TRADE_SUCCESS = "TRADE_SUCCESS",
27
    // 交易关闭
28
    TRADE_CLOSED = "TRADE_CLOSED"
29
 */
30
class QRCode
31
{
32
    protected $type = 'QR_TYPE_DYNAMIC';
33
34
    /**
35
     * @var int
36
     */
37
    protected $id;
38
39
    /**
40
     * @var int
41
     */
42
    protected $price;
43
44
    /**
45
     * @var string
46
     */
47
    protected $name;
48
49
    /**
50
     * @var string
51
     */
52
    protected $source;
53
54
    /**
55
     * @var string
56
     */
57
    protected $code;
58
59
    /**
60
     * @var string
61
     */
62
    protected $url;
63
64
    public function __construct($price = null, $name = null, $source = null)
65
    {
66
        $price && $this->setPrice($price);
67
        $this->name = $name;
68
        $this->source = $source;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getType()
75
    {
76
        return $this->type;
77
    }
78
79
    /**
80
     * @param string $type
81
     *
82
     * @return QRCode
83
     */
84
    public function setType($type)
85
    {
86
        $this->type = $type;
87
88
        return $this;
89
    }
90
91
    /**
92
     * 获取价格
93
     *
94
     * @return int
95
     */
96
    public function getPrice()
97
    {
98
        return $this->price;
99
    }
100
101
    /**
102
     * 设置收取的价格
103
     *
104
     * @param int|Amount $price
105
     *
106
     * @return QRCode
107
     */
108
    public function setPrice($price)
109
    {
110
        if ($price instanceof Amount) {
111
            $price = $price->getNumber();
112
        }
113
        $this->price = $price;
114
115
        return $this;
116
    }
117
118
    /**
119
     * 获取收款理由.
120
     *
121
     * @return string
122
     */
123
    public function getName()
124
    {
125
        return $this->name;
126
    }
127
128
    /**
129
     * 设置收款理由.
130
     *
131
     * @param string $name
132
     *
133
     * @return QRCode
134
     */
135
    public function setName($name)
136
    {
137
        $this->name = $name;
138
139
        return $this;
140
    }
141
142
    /**
143
     * @return string
144
     */
145
    public function getSource()
146
    {
147
        return $this->source;
148
    }
149
150
    /**
151
     * @param string $source
152
     *
153
     * @return QRCode
154
     */
155
    public function setSource($source)
156
    {
157
        $this->source = $source;
158
159
        return $this;
160
    }
161
162
    /**
163
     * @return int
164
     */
165
    public function getId()
166
    {
167
        return $this->id;
168
    }
169
170
    /**
171
     * @param int $id
172
     *
173
     * @return QRCode
174
     */
175
    public function setId($id)
176
    {
177
        $this->id = $id;
178
179
        return $this;
180
    }
181
182
    /**
183
     * @return string
184
     */
185
    public function getCode()
186
    {
187
        return $this->code;
188
    }
189
190
    /**
191
     * @param string $code
192
     *
193
     * @return QRCode
194
     */
195
    public function setCode($code)
196
    {
197
        $this->code = $code;
198
199
        return $this;
200
    }
201
202
    /**
203
     * @return string
204
     */
205
    public function getUrl()
206
    {
207
        return $this->url;
208
    }
209
210
    /**
211
     * @param string $url
212
     *
213
     * @return QRCode
214
     */
215
    public function setUrl($url)
216
    {
217
        $this->url = $url;
218
219
        return $this;
220
    }
221
222
    /**
223
     * 从数组创建 charge 对象
224
     *
225
     * @param array $array
226
     *
227
     * @return QRCode
228
     */
229
    public static function fromArray($array)
230
    {
231
        if (array_diff_key(['name' => null, 'price' => null, 'source' => null], $array)) {
232
            throw new \InvalidArgumentException('You must provide an array of keys containing "name", "price" and "source"');
233
        }
234
235
        return new static($array['price'], $array['name'], $array['source']);
236
    }
237
}