GoogleCloudFsComponent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 12 3
A initAdapter() 0 12 1
1
<?php
2
3
namespace dosamigos\flysystem;
4
5
use CedricZiel\FlysystemGcs\GoogleCloudStorageAdapter;
6
use yii\base\InvalidConfigException;
7
8
class GoogleCloudFsComponent extends AbstractFsComponent
9
{
10
    /**
11
     * @var string
12
     */
13
    public $projectId;
14
    /**
15
     * @var string
16
     */
17
    public $bucket;
18
    /**
19
     * @var string
20
     */
21
    public $prefix;
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function init()
27
    {
28
        if ($this->projectId === null) {
29
            throw new InvalidConfigException('The "projectId" property must be set.');
30
        }
31
32
        if ($this->bucket === null) {
33
            throw new InvalidConfigException('The "bucket" property must be set.');
34
        }
35
36
        parent::init();
37
    }
38
39
    /**
40
     * @return GoogleCloudStorageAdapter
41
     */
42
    protected function initAdapter()
43
    {
44
        $config = array_filter(
45
            [
46
                'projectId' => $this->projectId,
47
                'bucket' => $this->bucket,
48
                'prefix' => $this->prefix
49
            ]
50
        );
51
52
        return new GoogleCloudStorageAdapter(null, $config);
53
    }
54
}
55