Client   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 36
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 15 3
A getCacheKey() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat\Payment\Sandbox;
13
14
use EasyWeChat\Kernel\Traits\InteractsWithCache;
15
use EasyWeChat\Payment\Kernel\BaseClient;
16
use EasyWeChat\Payment\Kernel\Exceptions\SandboxException;
17
18
/**
19
 * Class Client.
20
 *
21
 * @author mingyoung <[email protected]>
22
 */
23
class Client extends BaseClient
24
{
25
    use InteractsWithCache;
26
27
    /**
28
     * @return string
29
     *
30
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
31
     * @throws \EasyWeChat\Payment\Kernel\Exceptions\SandboxException
32
     * @throws \Psr\SimpleCache\InvalidArgumentException
33
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
34
     * @throws \GuzzleHttp\Exception\GuzzleException
35
     */
36 1
    public function getKey(): string
37
    {
38 1
        if ($cache = $this->getCache()->get($this->getCacheKey())) {
39 1
            return $cache;
40
        }
41
42 1
        $response = $this->requestArray('sandboxnew/pay/getsignkey');
43
44 1
        if ('SUCCESS' === $response['return_code']) {
45 1
            $this->getCache()->set($this->getCacheKey(), $key = $response['sandbox_signkey'], 24 * 3600);
46
47 1
            return $key;
48
        }
49
50 1
        throw new SandboxException($response['retmsg'] ?? $response['return_msg']);
51
    }
52
53
    /**
54
     * @return string
55
     */
56 2
    protected function getCacheKey(): string
57
    {
58 2
        return 'easywechat.payment.sandbox.'.md5($this->app['config']->app_id.$this->app['config']['mch_id']);
59
    }
60
}
61