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

Material::uploadImage()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 2
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
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