Passed
Push — master ( f75521...69da7a )
by alpha
02:40
created

AliyunOssConfig   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 42
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrlDomain() 0 6 3
A getOssEndpoint() 0 11 3
A getOssClientParameters() 0 11 2
1
<?php
2
3
namespace AlphaSnow\AliyunOss;
4
5
use Illuminate\Support\Collection;
6
7
class AliyunOssConfig extends Collection
8
{
9
    /**
10
     * @return string
11
     */
12 3
    public function getUrlDomain()
13
    {
14 3
        $protocol = $this->get('use_ssl', false) ? 'https' : 'http';
15 3
        $domain = $this->get('domain') ?: $this->get('bucket').'.'.$this->get('endpoint');
16 3
        return $protocol.'://'.$domain;
17
    }
18
19
    /**
20
     * @return string
21
     */
22 4
    public function getOssEndpoint()
23
    {
24 4
        if ($internal = $this->get('internal')) {
25
            return $internal;
26
        }
27 4
        if ($domain = $this->get('domain')) {
28 1
            return $domain;
29
        }
30
31 3
        return $this->get('endpoint');
32
    }
33
34
    /**
35
     * @return array
36
     */
37 4
    public function getOssClientParameters()
38
    {
39 4
        $isCName = $this->get('domain') ? true : false;
40
        return [
41 4
            'accessKeyId' => $this->get('access_id'),
42 4
            'accessKeySecret' => $this->get('access_key'),
43 4
            'endpoint' => $this->getOssEndpoint(),
44 4
            'isCName' => $isCName,
45 4
            'securityToken' => $this->get('security_token', null)
46
        ];
47
    }
48
}
49