Passed
Push — master ( 38a3bd...8d4205 )
by alpha
02:31
created

AliyunOssConfig::isCName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 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 5
    public function getUrlDomain()
13
    {
14 5
        $protocol = $this->get('use_ssl', false) ? 'https' : 'http';
15 5
        $domain = $this->get('domain') ?: $this->get('bucket').'.'.$this->get('endpoint');
16 5
        return $protocol.'://'.$domain;
17
    }
18
19 2
    public function getInternalDomain()
20
    {
21 2
        $protocol = $this->get('use_ssl', false) ? 'https' : 'http';
22 2
        return $protocol.'://'.$this->get('bucket').'.'.$this->get('internal');
23
    }
24
25
    /**
26
     * @return string
27
     */
28 4
    public function getOssEndpoint()
29
    {
30 4
        if ($this->isCName()) {
31 1
            return $this->get('domain');
32
        }
33 4
        if ($internal = $this->get('internal')) {
34 4
            return $internal;
35
        }
36 1
        return $this->get('endpoint');
37
    }
38
39 4
    public function isCName()
40
    {
41 4
        return $this->get('use_domain_endpoint') && $this->get('domain');
42
    }
43
44
    /**
45
     * @return array
46
     */
47 3
    public function getOssClientParameters()
48
    {
49
        return [
50 3
            'accessKeyId' => $this->get('access_id'),
51 3
            'accessKeySecret' => $this->get('access_key'),
52 3
            'endpoint' => $this->getOssEndpoint(),
53 3
            'isCName' => $this->isCName(),
54 3
            'securityToken' => $this->get('security_token', null)
55
        ];
56
    }
57
}
58