Failed Conditions
Push — master ( 493ca2...80c807 )
by Florian
08:07 queued 04:14
created

AzureFactory::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 15
ccs 0
cts 12
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * Copyright (c) Florian Krämer (https://florian-kraemer.net)
5
 * Licensed under The MIT License
6
 * For full copyright and license information, please see the LICENSE.txt
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net)
10
 * @author    Florian Krämer
11
 * @link      https://github.com/Phauthentic
12
 * @license   https://opensource.org/licenses/MIT MIT License
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phauthentic\Infrastructure\Storage\Factories;
18
19
use League\Flysystem\AdapterInterface;
20
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
21
use MicrosoftAzure\Storage\Common\ServicesBuilder;
22
23
/**
24
 * AzureFactory
25
 */
26
class AzureFactory extends AbstractFactory
27
{
28
    protected string $alias = 'azure';
29
    protected ?string $package = 'league/flysystem-azure-blob-storage';
30
    protected string $className = AzureBlobStorageAdapter::class;
31
32
    protected $endpoint = 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s';
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public function build($config): AdapterInterface
38
    {
39
        $this->availabilityCheck();
40
41
        $endpoint = sprintf(
42
            $this->endpoint,
43
            base64_encode($config['accountName'] ?? ''),
44
            base64_encode($config['apiKey'] ?? '')
45
        );
46
47
        $client = ServicesBuilder::getInstance()->createBlobService($endpoint);
0 ignored issues
show
Unused Code introduced by
The assignment to $client is dead and can be removed.
Loading history...
48
49
        return new AzureBlobStorageAdapter(
50
            ServicesBuilder::getInstance()->createBlobService($endpoint),
51
            $config['container']
52
        );
53
    }
54
}
55