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

DouyinConfig::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Config;
6
7
class DouyinConfig implements ConfigInterface
8
{
9
    public function __construct(
10
        public string $mini_app_id,
11
        public string $mch_secret_token,
12
        public string $mch_secret_salt,
13
        public string $mch_id = '',
14
        public string $thirdparty_id = '',
15
        public string $notify_url = '',
16
    ) {
17
    }
18
19
    public function toArray(): array
20
    {
21
        return [
22
            'mch_id' => $this->mch_id,
23
            'mch_secret_token' => $this->mch_secret_token,
24
            'mch_secret_salt' => $this->mch_secret_salt,
25
            'mini_app_id' => $this->mini_app_id,
26
            'thirdparty_id' => $this->thirdparty_id,
27
            'notify_url' => $this->notify_url,
28
        ];
29
    }
30
31
    public static function fromArray(array $config): self
32
    {
33
        return new self(
34
            mini_app_id: $config['mini_app_id'] ?? '',
35
            mch_secret_token: $config['mch_secret_token'] ?? '',
36
            mch_secret_salt: $config['mch_secret_salt'] ?? '',
37
            mch_id: $config['mch_id'] ?? '',
38
            thirdparty_id: $config['thirdparty_id'] ?? '',
39
            notify_url: $config['notify_url'] ?? '',
40
        );
41
    }
42
}
43