Passed
Push — master ( a47d4f...4246e8 )
by Jared
02:15
created

AnyCloudFactory::createUri()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 2
nop 0
dl 0
loc 8
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
22
    /**
23
     * @param ContainerInterface $serviceLocator
24
     * @param string             $requestedName
25
     * @param array|null         $options
26
     *
27
     * @return AnyCloud|object
28
     */
29
    public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
30
    {
31
        $this->options = $serviceLocator->get('Omeka\Settings');
32
        $this->createFilesystem();
33
        $this->createUri();
34
35
        return new AnyCloud($this->filesystem, $this->options, $this->uri, $this->adapter);
36
    }
37
38
    /**
39
     * Create the Filesystem object
40
     */
41
    private function createFilesystem()
42
    {
43
        $adapterName = $this->getAdapter();
44
        switch ($adapterName) {
45
            case 'aws':
46
            case 'digital_ocean':
47
            case 'scaleway':
48
                $aws = new Adapter\AwsAdapter;
49
                $this->adapter = $aws->createAdapter($this->options);
50
                break;
51
            case 'azure':
52
                $azure = new Adapter\AzureAdapter;
53
                $this->adapter = $azure->createAdapter($this->options);
54
                $this->tempUri = $azure->getUri();
55
                break;
56
            case 'rackspace':
57
                $rackspace = new Adapter\RackspaceAdapter;
58
                $this->adapter = $rackspace->createAdapter($this->options);
59
                $this->tempUri = $rackspace->getUri();
60
                break;
61
            case 'dropbox':
62
                $dropbox = new Adapter\DropboxAdapter;
63
                $this->adapter = $dropbox->createAdapter($this->options);
64
                break;
65
            case 'google':
66
                $google = new Adapter\GoogleAdapter;
67
                $this->adapter = $google->createAdapter($this->options);
68
                $this->tempUri = $google->getUri();
69
                break;
70
            default:
71
                $this->adapter = null;
72
        }
73
74
        $this->filesystem = new Filesystem($this->adapter);
0 ignored issues
show
Bug introduced by
It seems like $this->adapter can also be of type null; however, parameter $adapter of League\Flysystem\Filesystem::__construct() does only seem to accept League\Flysystem\AdapterInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

74
        $this->filesystem = new Filesystem(/** @scrutinizer ignore-type */ $this->adapter);
Loading history...
75
    }
76
77
    /**
78
     * Create URI for file
79
     */
80
    private function createUri()
81
    {
82
        $adapterName = $this->getAdapter();
83
        if($adapterName == 'aws' || $adapterName == 'digital_ocean' || $adapterName == 'scaleway') {
84
            $this->uri = dirname($this->filesystem->getAdapter()->getClient()->getObjectUrl($this->getSetting('bucket'),
85
                $this->getSetting('key')));
86
        } else {
87
            $this->uri = $this->tempUri;
88
        }
89
    }
90
}
91