AzureFsComponent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 13 4
A initAdapter() 0 11 1
1
<?php
2
/**
3
 * This file is part of the 2amigos/yii2-flysystem-component project.
4
 *
5
 * (c) 2amigOS! <http://2amigos.us/>
6
 *
7
 * For the full copyright and license information, please view
8
 * the LICENSE file that was distributed with this source code.
9
 */
10
namespace dosamigos\flysystem;
11
12
use League\Flysystem\Azure\AzureAdapter;
13
use MicrosoftAzure\Storage\Common\ServicesBuilder;
14
use yii\base\InvalidConfigException;
15
16
class AzureFsComponent extends AbstractFsComponent
17
{
18
    /**
19
     * @var string
20
     */
21
    public $accountName;
22
    /**
23
     * @var string
24
     */
25
    public $accountKey;
26
    /**
27
     * @var string
28
     */
29
    public $container;
30
    /**
31
     * @inheritdoc
32
     */
33
    public function init()
34
    {
35
        if ($this->accountName === null) {
36
            throw new InvalidConfigException('The "accountName" property must be set.');
37
        }
38
        if ($this->accountKey === null) {
39
            throw new InvalidConfigException('The "accountKey" property must be set.');
40
        }
41
        if ($this->container === null) {
42
            throw new InvalidConfigException('The "container" property must be set.');
43
        }
44
        parent::init();
45
    }
46
    /**
47
     * @return AzureAdapter
48
     */
49
    protected function initAdapter()
50
    {
51
        return new AzureAdapter(
52
            ServicesBuilder::getInstance()->createBlobService(sprintf(
53
                'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
54
                base64_encode($this->accountName),
55
                base64_encode($this->accountKey)
56
            )),
57
            $this->container
58
        );
59
    }
60
}
61