Passed
Push — master ( 18c6ea...5297af )
by alpha
14:38
created

OssClientAdapter::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
1
<?php
2
3
namespace AlphaSnow\LaravelFilesystem\Aliyun;
4
5
use AlphaSnow\Flysystem\Aliyun\AliyunAdapter;
6
use AlphaSnow\Flysystem\Aliyun\AliyunException;
7
use Illuminate\Filesystem\FilesystemAdapter;
8
use League\Flysystem\Config;
9
10
class OssClientAdapter
11
{
12
    /**
13
     * @var AliyunAdapter
14
     */
15
    protected $adapter;
16
17
    /**
18
     * @param FilesystemAdapter $filesystemAdapter
19
     */
20 2
    public function __construct(FilesystemAdapter $filesystemAdapter)
21
    {
22 2
        $adapter = $filesystemAdapter->getAdapter();
23 2
        if (!$adapter instanceof AliyunAdapter) {
24
            throw new AliyunException("Adapter expect AliyunAdapter, But got ".$adapter::class, 0);
25
        }
26 2
        $this->adapter = $adapter;
27
    }
28
29
    /**
30
     * @return \OSS\OssClient
31
     */
32 2
    public function client()
33
    {
34 2
        return $this->adapter->getClient();
35
    }
36
37
    /**
38
     * @param string $bucket
39
     * @return string
40
     */
41 2
    public function bucket($bucket = "")
42
    {
43 2
        return $bucket == "" ? $this->adapter->getBucket() : $bucket;
44
    }
45
46
    /**
47
     * @param string $path
48
     * @return string
49
     */
50 2
    public function path($path = "")
51
    {
52 2
        return $this->adapter->getPrefixer()->prefixPath($path);
53
    }
54
55
    /**
56
     * @param array $options
57
     * @return array
58
     */
59 2
    public function options($options = [])
60
    {
61 2
        return $this->adapter->getOptions()->mergeConfig(new Config($options));
62
    }
63
}
64