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

RackspaceFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 19
dl 0
loc 37
ccs 0
cts 13
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 9 1
A buildClient() 0 5 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\Rackspace\RackspaceAdapter;
21
use OpenCloud\Rackspace;
22
23
/**
24
 * RackspaceFactory
25
 */
26
class RackspaceFactory extends AbstractFactory
27
{
28
    protected string $alias = 'rackspace';
29
    protected ?string $package = 'league/flysystem-rackspace';
30
    protected string $className = RackspaceAdapter::class;
31
    protected array $defaults = [
32
        'identityEndpoint' => Rackspace::UK_IDENTITY_ENDPOINT,
33
        'username' => '',
34
        'apiKey' => '',
35
        'objectStoreService' => 'cloudFiles',
36
        'serviceRegion' => 'LON',
37
        'container' => 'flysystem'
38
    ];
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function build(array $config): AdapterInterface
44
    {
45
        $config = array_merge($this->defaults, $config);
46
47
        $client = $this->buildClient($config);
48
        $store = $client->objectStoreService($config['serviceName'], $config['serviceRegion']);
49
        $container = $store->getContainer($config['container']);
50
51
        return new RackspaceAdapter($container);
52
    }
53
54
    /**
55
     * @param array $config Config
56
     * @return \OpenCloud\Rackspace
57
     */
58
    protected function buildClient(array $config): Rackspace
59
    {
60
        return new Rackspace($config['identityEndpoint'], array(
61
            'username' => $config['username'],
62
            'apiKey' => $config['apiKey'],
63
        ));
64
    }
65
}
66