Passed
Pull Request — master (#1124)
by
unknown
03:55 queued 01:03
created

JsbConfig::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Config;
6
7
use Yansongda\Pay\Pay;
8
9
class JsbConfig implements ConfigInterface
10
{
11
    public function __construct(
12
        public string $partner_id,
13
        public string $mch_secret_cert_path,
14
        public string $mch_public_cert_path,
15
        public string $jsb_public_cert_path,
16
        public string $svr_code = '',
17
        public string $public_key_code = '00',
18
        public string $notify_url = '',
19
        public int $mode = Pay::MODE_NORMAL,
20
    ) {
21
    }
22
23
    public function toArray(): array
24
    {
25
        return [
26
            'svr_code' => $this->svr_code,
27
            'partner_id' => $this->partner_id,
28
            'public_key_code' => $this->public_key_code,
29
            'mch_secret_cert_path' => $this->mch_secret_cert_path,
30
            'mch_public_cert_path' => $this->mch_public_cert_path,
31
            'jsb_public_cert_path' => $this->jsb_public_cert_path,
32
            'notify_url' => $this->notify_url,
33
            'mode' => $this->mode,
34
        ];
35
    }
36
37
    public static function fromArray(array $config): self
38
    {
39
        return new self(
40
            partner_id: $config['partner_id'] ?? '',
41
            mch_secret_cert_path: $config['mch_secret_cert_path'] ?? '',
42
            mch_public_cert_path: $config['mch_public_cert_path'] ?? '',
43
            jsb_public_cert_path: $config['jsb_public_cert_path'] ?? '',
44
            svr_code: $config['svr_code'] ?? '',
45
            public_key_code: $config['public_key_code'] ?? '00',
46
            notify_url: $config['notify_url'] ?? '',
47
            mode: $config['mode'] ?? Pay::MODE_NORMAL,
48
        );
49
    }
50
}
51