Passed
Push — master ( bdadf0...34cc72 )
by
unknown
05:20
created

AnyCloudFactory::createRackspaceAdapter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace AnyCloud\Service\File\Store;
4
5
use AnyCloud\File\Store\AnyCloud;
6
use AnyCloud\Service\File\Adapter;
7
use AnyCloud\Traits\CommonTrait;
8
use Interop\Container\ContainerInterface;
9
use Laminas\ServiceManager\Factory\FactoryInterface;
0 ignored issues
show
Bug introduced by
The type Laminas\ServiceManager\Factory\FactoryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use League\Flysystem\Filesystem;
11
12
class AnyCloudFactory implements FactoryInterface
13
{
14
    use CommonTrait;
15
16
    private const AWS_BASED = ['aws', 'wasabi', 'digital_ocean', 'scaleway'];
17
18
    protected $options;
19
    private $filesystem;
20
    private $uri;
21
    private $tempUri;
22
    private $adapter;
23
24
    /**
25
     * @param ContainerInterface $serviceLocator
26
     * @param string             $requestedName
27
     * @param array|null         $options
28
     *
29
     * @return AnyCloud|object
30
     */
31
    public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
32
    {
33
        $this->options = $serviceLocator->get('Omeka\Settings');
34
        $this->createFilesystem();
35
        $this->createUri();
36
37
        return new AnyCloud($this->filesystem, $this->options, $this->uri, $this->adapter);
38
    }
39
40
    /**
41
     * Create the Filesystem object.
42
     */
43
    private function createFilesystem(): void
44
    {
45
        $this->createAwsAdapter();
46
        $this->createAzureAdapter();
47
        $this->createDropboxAdapter();
48
        $this->createGoogleAdapter();
49
50
        $this->filesystem = new Filesystem($this->adapter);
51
    }
52
53
    /**
54
     * Create adapter.
55
     *
56
     * @param object $adapter Adapter to create
57
     */
58
    private function createAdapter($adapter): void
59
    {
60
        $this->adapter = $adapter->createAdapter($this->options);
61
    }
62
63
    /**
64
     * Create a temporary URI to store the file before saving.
65
     *
66
     * @param object $adapter Adapter to create a temporary URI for
67
     */
68
    private function createTempUri($adapter): void
69
    {
70
        $this->tempUri = $adapter->getUri();
71
    }
72
73
    /**
74
     * Create new AWS adapter.
75
     */
76
    private function createAwsAdapter(): void
77
    {
78
        if (in_array($this->getAdapter(), self::AWS_BASED, true)) {
79
            $this->createAdapter(new Adapter\AwsAdapter());
80
        }
81
    }
82
83
    /**
84
     * Create new Azure adapter.
85
     */
86
    private function createAzureAdapter(): void
87
    {
88
        if ($this->getAdapter() === 'azure') {
89
            $adapter = new Adapter\AzureAdapter();
90
            $this->createAdapter($adapter);
91
            $this->createTempUri($adapter);
92
        }
93
    }
94
95
    /**
96
     * Create new Dropbox adapter.
97
     */
98
    private function createDropboxAdapter(): void
99
    {
100
        if ($this->getAdapter() === 'dropbox') {
101
            $adapter = new Adapter\DropboxAdapter();
102
            $this->createAdapter($adapter);
103
        }
104
    }
105
106
    /**
107
     * Create new Google adapter.
108
     */
109
    private function createGoogleAdapter(): void
110
    {
111
        if ($this->getAdapter() === 'google') {
112
            $adapter = new Adapter\GoogleAdapter();
113
            $this->createAdapter($adapter);
114
            $this->createTempUri($adapter);
115
        }
116
    }
117
118
    /**
119
     * Create URI for file.
120
     */
121
    private function createUri(): void
122
    {
123
        $this->uri = $this->tempUri;
124
    }
125
}
126