AzureFactory::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
23
use Phauthentic\Infrastructure\Storage\Factories\Exception\FactoryConfigException;
24
use Phauthentic\Infrastructure\Storage\Factories\Exception\FactoryException;
25
26
/**
27
 * Azure Factory
28
 *
29
 * Be aware that this adapter seems to have some problems!
30
 *
31
 * @link https://github.com/thephpleague/flysystem-azure/issues/22
32
 * @link https://github.com/thephpleague/flysystem-azure/issues/15
33
 */
34
class AzureFactory extends AbstractFactory
35
{
36
    protected string $alias = 'azure';
37
    protected ?string $package = 'league/flysystem-azure-blob-storage';
38
    protected string $className = AzureBlobStorageAdapter::class;
39
40
    protected $endpoint = 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s';
41
42
    /**
43
     * @inheritDoc
44
     */
45 1
    public function build($config): AdapterInterface
46
    {
47 1
        $this->availabilityCheck();
48 1
        $this->checkConfig($config);
49
50 1
        $endpoint = sprintf(
51 1
            $this->endpoint,
52 1
            base64_encode($config['accountName']),
53 1
            base64_encode($config['apiKey'])
54
        );
55
56 1
        $client = BlobRestProxy::createBlobService($endpoint);
0 ignored issues
show
Bug introduced by
The method createBlobService() does not exist on MicrosoftAzure\Storage\Blob\BlobRestProxy. Did you maybe mean createBlobPages()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        /** @scrutinizer ignore-call */ 
57
        $client = BlobRestProxy::createBlobService($endpoint);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
58 1
        return new AzureBlobStorageAdapter($client, $config['accountName']);
59
    }
60
61 1
    protected function checkConfig(array $config): void
62
    {
63 1
        if (empty($config['accountName'])) {
64
            throw FactoryConfigException::withMissingKey('apiKey', $this);
65
        }
66
67 1
        if (empty($config['apiKey'])) {
68
            throw FactoryConfigException::withMissingKey('apiKey', $this);
69
        }
70 1
    }
71
}
72