Passed
Pull Request — master (#42)
by
unknown
15:10
created

AbstractFlysystemFactory::getConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 19
rs 9.8666
1
<?php
2
3
namespace AnyCloud\Service\File\Store;
4
5
use AnyCloud\File\Store\Flysystem;
6
use Interop\Container\ContainerInterface;
7
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...
8
use League\Flysystem\Filesystem;
9
use League\Flysystem\FilesystemAdapter;
10
use Omeka\File\Store\StoreInterface;
11
12
abstract class AbstractFlysystemFactory implements FactoryInterface
13
{
14
    abstract protected function getConfigKey(): string;
15
    abstract protected function getFilesystemAdapter(array $config): FilesystemAdapter;
16
17
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
18
    {
19
        $config = $this->getConfig($container);
20
        $store = $this->getStore($config);
21
22
        return $store;
23
    }
24
25
    protected function getConfig(ContainerInterface $container)
26
    {
27
        $config = $container->get('Config');
28
29
        $configKey = $this->getConfigKey();
30
        if (isset($config['file_store'][$configKey])) {
31
            return $config['file_store'][$configKey];
32
        }
33
34
        $settings = $container->get('Omeka\Settings');
35
        $db_settings = $settings->get("anycloud_$configKey", []);
36
        $adapter_config = [];
37
        $configKeyQuoted = preg_quote($configKey);
38
        foreach ($db_settings as $key => $value) {
39
            $new_key = preg_replace("/^{$configKeyQuoted}_/", '', $key);
40
            $adapter_config[$new_key] = $value;
41
        }
42
43
        return $adapter_config;
44
    }
45
46
    protected function getStore(array $config): StoreInterface
47
    {
48
        $adapter = $this->getFilesystemAdapter($config);
49
        $filesystem = new Filesystem($adapter);
50
        $store = new Flysystem($filesystem);
51
52
        return $store;
53
    }
54
}
55