Completed
Push — master ( 455325...7625db )
by Bas
06:55 queued 02:45
created

AzureAdapterFactory::doCreateService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 19
ccs 0
cts 0
cp 0
rs 9.4285
c 3
b 0
f 0
cc 2
eloc 12
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BsbFlysystem\Adapter\Factory;
6
7
use BsbFlysystem\Exception\RequirementsException;
8
use BsbFlysystem\Exception\UnexpectedValueException;
9
use League\Flysystem\AdapterInterface;
10
use League\Flysystem\Azure\AzureAdapter as Adapter;
11
use WindowsAzure\Common\ServicesBuilder;
12
use Zend\ServiceManager\ServiceLocatorInterface;
13
14
class AzureAdapterFactory extends AbstractAdapterFactory
15
{
16
    public function doCreateService(ServiceLocatorInterface $serviceLocator): AdapterInterface
17
    {
18
        if (! class_exists(\League\Flysystem\Azure\AzureAdapter::class)) {
19
            throw new RequirementsException(
20
                ['league/flysystem-azure'],
21
                'Azure'
22
            );
23
        }
24
        $endpoint      = sprintf(
25
            'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
26
            $this->options['account-name'],
27
            $this->options['account-key']
28
        );
29
30
        $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint);
31
        $adapter       = new Adapter($blobRestProxy, $this->options['container']);
32
33
        return $adapter;
34
    }
35
36 4
    protected function validateConfig()
37
    {
38 4
        if (! isset($this->options['account-name'])) {
39 1
            throw new UnexpectedValueException("Missing 'account-name' as option");
40
        }
41
42 3
        if (! isset($this->options['account-key'])) {
43 1
            throw new UnexpectedValueException("Missing 'account-key' as option");
44
        }
45
46 2
        if (! isset($this->options['container'])) {
47 1
            throw new UnexpectedValueException("Missing 'container' as option");
48
        }
49 1
    }
50
}
51