Client   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 25
ccs 0
cts 6
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A upload() 0 12 3
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\MicroMerchant\Media;
13
14
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
15
use EasyWeChat\MicroMerchant\Kernel\BaseClient;
16
17
/**
18
 * Class Client.
19
 *
20
 * @author   liuml  <[email protected]>
21
 * @DateTime 2019-06-10 14:50
22
 */
23
class Client extends BaseClient
24
{
25
    /**
26
     * Upload material.
27
     *
28
     * @param string $path
29
     *
30
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
31
     *
32
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
33
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
34
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
35
     */
36
    public function upload(string $path)
37
    {
38
        if (!file_exists($path) || !is_readable($path)) {
39
            throw new InvalidArgumentException(sprintf("File does not exist, or the file is unreadable: '%s'", $path));
40
        }
41
42
        $form = [
43
            'media_hash' => strtolower(md5_file($path)),
44
            'sign_type' => 'HMAC-SHA256',
45
        ];
46
47
        return $this->httpUpload('secapi/mch/uploadmedia', ['media' => $path], $form);
48
    }
49
}
50