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

OssService::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
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\aliyun;
21
22
use DtApp\ThinkLibrary\Service;
23
use OSS\Core\OssException;
24
use OSS\OssClient;
25
26
/**
27
 * 阿里云对象存储
28
 * https://www.aliyun.com/product/oss
29
 * Class OssService
30
 * @package DtApp\ThinkLibrary\service\aliyun
31
 */
32
class OssService extends Service
33
{
34
    /**
35
     * @var
36
     */
37
    private $accessKeyId, $accessKeySecret, $endpoint, $bucket;
38
39
    /**
40
     * @param string $accessKeyId
41
     * @return $this
42
     */
43
    public function accessKeyId(string $accessKeyId)
44
    {
45
        $this->accessKeyId = $accessKeyId;
46
        return $this;
47
    }
48
49
    /**
50
     * @param string $accessKeySecret
51
     * @return $this
52
     */
53
    public function accessKeySecret(string $accessKeySecret)
54
    {
55
        $this->accessKeySecret = $accessKeySecret;
56
        return $this;
57
    }
58
59
    /**
60
     * @param string $endpoint
61
     * @return $this
62
     */
63
    public function endpoint(string $endpoint): self
64
    {
65
        $this->endpoint = $endpoint;
66
        return $this;
67
    }
68
69
    /**
70
     * @param string $bucket
71
     * @return $this
72
     */
73
    public function bucket(string $bucket): self
74
    {
75
        $this->bucket = $bucket;
76
        return $this;
77
    }
78
79
    /**
80
     * @param string $object
81
     * @param string $filePath
82
     * @return string|null
83
     */
84
    public function upload(string $object, string $filePath): ?string
85
    {
86
        try {
87
            $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
88
            return $ossClient->uploadFile($this->bucket, $object, $filePath);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $ossClient->uploadFile($...et, $object, $filePath) targeting OSS\OssClient::uploadFile() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
89
        } catch (OssException $e) {
90
            return $e->getMessage();
91
        }
92
    }
93
}
94