MaterialClient   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 4
dl 0
loc 21
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A uploadImage() 0 7 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\OfficialAccount\ShakeAround;
13
14
use EasyWeChat\Kernel\BaseClient;
15
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
16
17
/**
18
 * Class MaterialClient.
19
 *
20
 * @author allen05ren <[email protected]>
21
 */
22
class MaterialClient extends BaseClient
23
{
24
    /**
25
     * Upload image material.
26
     *
27
     * @param string $path
28
     * @param string $type
29
     *
30
     * @return string
31
     *
32
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
33
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
34
     * @throws \GuzzleHttp\Exception\GuzzleException
35
     */
36 1
    public function uploadImage(string $path, string $type = 'icon')
37
    {
38 1
        if (!file_exists($path) || !is_readable($path)) {
39 1
            throw new InvalidArgumentException(sprintf('File does not exist, or the file is unreadable: "%s"', $path));
40
        }
41
42 1
        return $this->httpUpload('shakearound/material/add', ['media' => $path], [], ['type' => strtolower($type)]);
43
    }
44
}
45