Completed
Push — master ( 63cdb6...e2968d )
by Bas
06:46 queued 04:49
created

AzureAdapterFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 44
ccs 8
cts 8
cp 1
rs 10
c 3
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doCreateService() 0 19 2
A validateConfig() 0 14 4
1
<?php
2
3
namespace BsbFlysystem\Adapter\Factory;
4
5
use BsbFlysystem\Exception\RequirementsException;
6
use BsbFlysystem\Exception\UnexpectedValueException;
7
use League\Flysystem\Azure\AzureAdapter as Adapter;
8
use WindowsAzure\Common\ServicesBuilder;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\ServiceLocatorInterface;
11
12
class AzureAdapterFactory extends AbstractAdapterFactory
13
{
14
15
    /**
16
     * @inheritdoc
17
     */
18
    public function doCreateService(ServiceLocatorInterface $serviceLocator)
19
    {
20
        if (!class_exists(\League\Flysystem\Azure\AzureAdapter::class)) {
21
            throw new RequirementsException(
22
                ['league/flysystem-azure'],
23
                'Azure'
24
            );
25
        }
26
        $endpoint      = sprintf(
27
            'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
28
            $this->options['account-name'],
29
            $this->options['account-key']
30
        );
31
32
        $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint);
33
        $adapter       = new Adapter($blobRestProxy, $this->options['container']);
34
35
        return $adapter;
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41 4
    protected function validateConfig()
42
    {
43 4
        if (!isset($this->options['account-name'])) {
44 1
            throw new UnexpectedValueException("Missing 'account-name' as option");
45
        }
46
47 3
        if (!isset($this->options['account-key'])) {
48 1
            throw new UnexpectedValueException("Missing 'account-key' as option");
49
        }
50
51 2
        if (!isset($this->options['container'])) {
52 1
            throw new UnexpectedValueException("Missing 'container' as option");
53
        }
54 1
    }
55
}
56