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

AliyunOssConfig::getOssEndpoint()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 3.0416
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