Passed
Push — v6 ( 0ec70f...32f4f3 )
by 光春
03:48
created

UssService::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
// +----------------------------------------------------------------------
4
// | ThinkLibrary 6.0 for ThinkPhP 6.0
5
// +----------------------------------------------------------------------
6
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
7
// +----------------------------------------------------------------------
8
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
9
// +----------------------------------------------------------------------
10
// | 开源协议 ( https://mit-license.org )
11
// +----------------------------------------------------------------------
12
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
13
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
14
// | gitlab 仓库地址 :https://gitlab.com/liguangchun/thinklibrary
15
// | weixin 仓库地址 :https://git.weixin.qq.com/liguangchun/ThinkLibrary
16
// | huaweicloud 仓库地址 :https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git
17
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
18
// +----------------------------------------------------------------------
19
20
namespace DtApp\ThinkLibrary\service\upyun;
21
22
use DtApp\ThinkLibrary\Service;
23
use Exception;
24
use Upyun\Config;
25
use Upyun\Upyun;
26
27
/**
28
 * 又拍云存储
29
 * https://www.upyun.com/products/file-storage
30
 * Class UssService
31
 * @package DtApp\ThinkLibrary\service\upyun
32
 */
33
class UssService extends Service
34
{
35
    /**
36
     * @var
37
     */
38
    private $serviceName, $operatorName, $operatorPassword;
39
40
    /**
41
     * @param string $serviceName
42
     * @return $this
43
     */
44
    public function serviceName(string $serviceName)
45
    {
46
        $this->serviceName = $serviceName;
47
        return $this;
48
    }
49
50
    /**
51
     * @param string $operatorName
52
     * @return $this
53
     */
54
    public function operatorName(string $operatorName)
55
    {
56
        $this->operatorName = $operatorName;
57
        return $this;
58
    }
59
60
    /**
61
     * @param string $operatorPassword
62
     * @return $this
63
     */
64
    public function operatorPassword(string $operatorPassword)
65
    {
66
        $this->operatorPassword = $operatorPassword;
67
        return $this;
68
    }
69
70
    /**
71
     * @param string $object
72
     * @param string $filePath
73
     * @return array|bool
74
     * @throws Exception
75
     */
76
    public function upload(string $object, string $filePath)
77
    {
78
        $serviceConfig = new Config($this->serviceName, $this->operatorName, $this->operatorPassword);
79
        $client = new Upyun($serviceConfig);
80
        $file = fopen($filePath, 'r');
81
        return  $client->write($object, $file);
0 ignored issues
show
Bug introduced by
It seems like $file can also be of type false; however, parameter $content of Upyun\Upyun::write() does only seem to accept resource|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
        return  $client->write($object, /** @scrutinizer ignore-type */ $file);
Loading history...
82
    }
83
}
84