Passed
Push — master ( c2d9a1...7efa9f )
by Carlos
03:06 queued 29s
created

Client   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 5
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 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\OpenPlatform\Authorizer\MiniProgram\Material;
13
14
use EasyWeChat\Kernel\BaseClient;
15
use EasyWeChat\Kernel\Http\StreamResponse;
16
17
/**
18
 * Class Client.
19
 *
20
 * @author overtrue <[email protected]>
21
 */
22
class Client extends BaseClient
23
{
24
    /**
25
     * Allow media type.
26
     *
27
     * @var array
28
     */
29
    protected $allowTypes = ['image', 'voice', 'video', 'thumb', 'news_image'];
30
31
    /**
32
     * Fetch material.
33
     *
34
     * @param string $mediaId
35
     *
36
     * @return mixed
37
     *
38
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
39
     * @throws \GuzzleHttp\Exception\GuzzleException
40
     */
41
    public function get(string $mediaId)
42
    {
43
        $response = $this->requestRaw('cgi-bin/material/get_material', 'POST', ['json' => ['media_id' => $mediaId]]);
44
45
        if (false !== stripos($response->getHeaderLine('Content-disposition'), 'attachment')) {
46
            return StreamResponse::buildFromPsrResponse($response);
47
        }
48
49
        return $this->castResponseToType($response, $this->app['config']->get('response_type'));
50
    }
51
}
52