Completed
Push — master ( a0e8ce...60fa13 )
by Bas
12s
created

AzureAdapterFactory::validateConfig()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.2
c 1
b 0
f 0
cc 4
eloc 7
nc 4
nop 0
crap 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