Completed
Push — master ( 058da3...8d02ae )
by Carlos
05:22 queued 02:18
created

Material   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A uploadImage() 0 10 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
/**
13
 * Material.php.
14
 *
15
 * @author    allen05ren <[email protected]>
16
 * @copyright 2016 overtrue <[email protected]>
17
 *
18
 * @see       https://github.com/overtrue
19
 * @see       http://overtrue.me
20
 */
21
22
namespace EasyWeChat\ShakeAround;
23
24
use EasyWeChat\Core\AbstractAPI;
25
use EasyWeChat\Core\Exceptions\InvalidArgumentException;
26
27
/**
28
 * Class Material.
29
 */
30
class Material extends AbstractAPI
31
{
32
    const API_MATERIAL_ADD = 'https://api.weixin.qq.com/shakearound/material/add';
33
34
    /**
35
     * Upload image material.
36
     *
37
     * @param string $path
38
     * @param string $type
39
     *
40
     * @return string
41
     *
42
     * @throws InvalidArgumentException
43
     */
44 1
    public function uploadImage($path, $type = 'icon')
45
    {
46 1
        if (!file_exists($path) || !is_readable($path)) {
47 1
            throw new InvalidArgumentException("File does not exist, or the file is unreadable: '$path'");
48
        }
49
50 1
        $type = strtolower($type);
51
52 1
        return $this->parseJSON('upload', [self::API_MATERIAL_ADD, ['media' => $path], [], ['type' => $type]]);
53
    }
54
}
55