Bos::createAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
ccs 14
cts 14
cp 1
crap 1
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace think\filesystem\driver;
6
7
use League\Flysystem\FilesystemAdapter;
8
use Sulao\BaiduBos\Client;
9
use Sulao\Flysystem\BaiduBos\BaiduBosAdapter;
10
use think\filesystem\Driver;
11
12
class Bos extends Driver
13
{
14
    protected $config = [];
15
16 1
    protected function createAdapter(): FilesystemAdapter
17
    {
18 1
        $config = $this->config + [
19 1
            'disable_asserts' => true,
20 1
            'case_sensitive' => true,
21 1
            'options' => [],
22 1
        ];
23
24 1
        $client = new Client([
25 1
            'access_key' => $config['access_key'],
26 1
            'secret_key' => $config['secret_key'],
27 1
            'bucket' => $config['bucket'],
28 1
            'region' => $config['region'],
29 1
            'options' => $config['options']
30 1
        ]);
31
32 1
        return new BaiduBosAdapter($client);
33
    }
34
35 1
    public function url(string $path): string
36
    {
37 1
        if (isset($this->config['url'])) {
38 1
            return $this->concatPathToUrl($this->config['url'], $path);
39
        }
40
41 1
        return $this->concatPathToUrl(
42 1
            "https://{$this->config['bucket']}.{$this->config['region']}.bcebos.com",
43 1
            $path
44 1
        );
45
    }
46
}
47