Passed
Push — master ( e1a506...99721f )
by alpha
02:00
created

AliyunOssAdapter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 3
dl 0
loc 74
ccs 16
cts 24
cp 0.6667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getOptionsFromConfig() 0 11 3
A getUrl() 0 19 3
A getTemporaryUrl() 0 8 1
1
<?php
2
3
namespace AlphaSnow\AliyunOss;
4
5
use Aliyun\Flysystem\AliyunOss\AliyunOssAdapter as BaseAdapter;
6
use League\Flysystem\Adapter\CanOverwriteFiles;
7
use League\Flysystem\AdapterInterface;
8
use League\Flysystem\Config;
9
use OSS\OssClient;
10
11
/**
12
 * Class AliyunOssAdapter
13
 * @package AlphaSnow\AliyunOss
14
 */
15
class AliyunOssAdapter extends BaseAdapter implements CanOverwriteFiles
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $config;
21
22 3
    public function __construct(OssClient $client, array $config)
23
    {
24 3
        $this->config = $config;
25 3
        parent::__construct($client, $config['bucket'], $config['prefix'], $config['options']);
26 3
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    protected function getOptionsFromConfig(Config $config)
32
    {
33 1
        $options = parent::getOptionsFromConfig($config);
34
35 1
        if ($visibility = $config->get('visibility')) {
36
            // Object ACL > Bucket ACL
37
            $options[OssClient::OSS_OBJECT_ACL] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE;
38
        }
39
40 1
        return $options;
41
    }
42
43
    /**
44
     * Used by \Illuminate\Filesystem\FilesystemAdapter::url
45
     *
46
     * @param string $path
47
     * @return string
48
     */
49 1
    public function getUrl($path)
50
    {
51 1
        $url = '';
52
53 1
        if ($this->config['ssl']) {
54
            $url .= 'https://';
55
        } else {
56 1
            $url .= 'http://';
57
        }
58
59 1
        if ($this->config['isCname']) {
60
            $url .= $this->config['cdnDomain'];
61
        } else {
62 1
            $url .= $this->config['bucket'] . '.' . $this->config['endpoint'];
63
        }
64
65 1
        $url .= '/' . ltrim($path, '/');
66 1
        return $url;
67
    }
68
69
    /**
70
     * Used by \Illuminate\Filesystem\FilesystemAdapter::temporaryUrl
71
     * Get a temporary URL for the file at the given path.
72
     *
73
     * @param string $path
74
     * @param \DateTimeInterface $expiration
75
     * @param array $options
76
     * @return string
77
     *
78
     * @throws \RuntimeException
79
     */
80
    public function getTemporaryUrl($path, $expiration, array $options = [])
81
    {
82
        $object = $this->applyPathPrefix($path);
83
        $clientOptions = $this->getOptionsFromConfig(new Config($options));
84
        $timeout = $expiration->getTimestamp() - time();
85
86
        return $this->client->signUrl($this->bucket, $object, $timeout, $clientOptions);
0 ignored issues
show
Documentation introduced by
$clientOptions is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
87
    }
88
}
89