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

AzureAdapterFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateConfig() 0 14 4
A doCreateService() 0 19 2
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