Passed
Push — master ( fe35f4...b5dd62 )
by Jared
02:05
created

AnyCloudFactory::createFilesystem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
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 League\Flysystem\Filesystem;
9
use Interop\Container\ContainerInterface;
1 ignored issue
show
Bug introduced by
The type Interop\Container\ContainerInterface 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 Zend\ServiceManager\Factory\FactoryInterface;
1 ignored issue
show
Bug introduced by
The type Zend\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...
11
12
class AnyCloudFactory implements FactoryInterface
13
{
14
    use CommonTrait;
15
16
    protected $options;
17
    private $filesystem;
18
    private $uri;
19
    private $tempUri;
20
    private $adapter;
21
    const AWS_BASED = ['aws', 'digital_ocean', 'scaleway'];
22
23
    /**
24
     * @param ContainerInterface $serviceLocator
25
     * @param string             $requestedName
26
     * @param array|null         $options
27
     *
28
     * @return AnyCloud|object
29
     */
30
    public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
31
    {
32
        $this->options = $serviceLocator->get('Omeka\Settings');
33
        $this->createFilesystem();
34
        $this->createUri();
35
36
        return new AnyCloud($this->filesystem, $this->options, $this->uri, $this->adapter);
37
    }
38
39
    /**
40
     * Create the Filesystem object
41
     */
42
    private function createFilesystem()
43
    {
44
        if(in_array($this->getAdapter(), self::AWS_BASED)) {
45
            $adapter = new Adapter\AwsAdapter;
46
            $this->adapter = $adapter->createAdapter($this->options);
47
        } else {
48
            $adapter = new Adapter\AzureAdapter;
49
            $this->adapter = $adapter->createAdapter($this->options);
50
            $this->tempUri = $adapter->getUri();
51
        }
52
53
        $this->filesystem = new Filesystem($this->adapter);
54
    }
55
56
    /**
57
     * Create URI for file
58
     */
59
    private function createUri()
60
    {
61
        if(in_array($this->getAdapter(), self::AWS_BASED)) {
62
            $this->uri = dirname($this->filesystem->getAdapter()->getClient()->getObjectUrl($this->getSetting('bucket'),
63
                $this->getSetting('key')));
64
        } else {
65
            $this->uri = $this->tempUri;
66
        }
67
    }
68
}
69