Client   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 69
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getQrCode() 0 3 1
A get() 0 7 1
A getUnlimit() 0 7 1
A getStream() 0 9 2
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\MiniProgram\AppCode;
13
14
use EasyWeChat\Kernel\BaseClient;
15
use EasyWeChat\Kernel\Http\StreamResponse;
16
17
/**
18
 * Class Client.
19
 *
20
 * @author mingyoung <[email protected]>
21
 */
22
class Client extends BaseClient
23
{
24
    /**
25
     * Get AppCode.
26
     *
27
     * @param string $path
28
     * @param array  $optional
29
     *
30
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
31
     */
32 2
    public function get(string $path, array $optional = [])
33
    {
34 2
        $params = array_merge([
35 2
            'path' => $path,
36
        ], $optional);
37
38 2
        return $this->getStream('wxa/getwxacode', $params);
39
    }
40
41
    /**
42
     * Get AppCode unlimit.
43
     *
44
     * @param string $scene
45
     * @param array  $optional
46
     *
47
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
48
     */
49 1
    public function getUnlimit(string $scene, array $optional = [])
50
    {
51 1
        $params = array_merge([
52 1
            'scene' => $scene,
53
        ], $optional);
54
55 1
        return $this->getStream('wxa/getwxacodeunlimit', $params);
56
    }
57
58
    /**
59
     * Create QrCode.
60
     *
61
     * @param string   $path
62
     * @param int|null $width
63
     *
64
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
65
     */
66 1
    public function getQrCode(string $path, int $width = null)
67
    {
68 1
        return $this->getStream('cgi-bin/wxaapp/createwxaqrcode', compact('path', 'width'));
69
    }
70
71
    /**
72
     * Get stream.
73
     *
74
     * @param string $endpoint
75
     * @param array  $params
76
     *
77
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
78
     *
79
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
80
     * @throws \GuzzleHttp\Exception\GuzzleException
81
     */
82 4
    protected function getStream(string $endpoint, array $params)
83
    {
84 4
        $response = $this->requestRaw($endpoint, 'POST', ['json' => $params]);
85
86 4
        if (false !== stripos($response->getHeaderLine('Content-disposition'), 'attachment')) {
87 3
            return StreamResponse::buildFromPsrResponse($response);
88
        }
89
90 1
        return $this->castResponseToType($response, $this->app['config']->get('response_type'));
91
    }
92
}
93