Passed
Push — master ( ea7aad...a7d002 )
by alpha
02:37
created

AliyunOssConfig::getInternalDomain()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
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 3
    public function getOssEndpoint()
29
    {
30 3
        if ($internal = $this->get('internal')) {
31 3
            return $internal;
32
        }
33
        if ($domain = $this->get('domain')) {
34
            return $domain;
35
        }
36
37
        return $this->get('endpoint');
38
    }
39
40
    /**
41
     * @return array
42
     */
43 3
    public function getOssClientParameters()
44
    {
45 3
        $isCName = $this->get('domain') ? true : false;
46
        return [
47 3
            'accessKeyId' => $this->get('access_id'),
48 3
            'accessKeySecret' => $this->get('access_key'),
49 3
            'endpoint' => $this->getOssEndpoint(),
50 3
            'isCName' => $isCName,
51 3
            'securityToken' => $this->get('security_token', null)
52
        ];
53
    }
54
}
55