Passed
Pull Request — master (#42)
by
unknown
08:12 queued 05:35
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
16
    abstract protected function getFilesystemAdapter(array $config): FilesystemAdapter;
17
18
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
19
    {
20
        $config = $this->getConfig($container);
21
        $store = $this->getStore($config);
22
23
        return $store;
24
    }
25
26
    protected function getConfig(ContainerInterface $container)
27
    {
28
        $config = $container->get('Config');
29
30
        $configKey = $this->getConfigKey();
31
        if (isset($config['file_store'][$configKey])) {
32
            return $config['file_store'][$configKey];
33
        }
34
35
        $settings = $container->get('Omeka\Settings');
36
        $db_settings = $settings->get("anycloud_$configKey", []);
37
        $adapter_config = [];
38
        $configKeyQuoted = preg_quote($configKey);
39
        foreach ($db_settings as $key => $value) {
40
            $new_key = preg_replace("/^{$configKeyQuoted}_/", '', $key);
41
            $adapter_config[$new_key] = $value;
42
        }
43
44
        return $adapter_config;
45
    }
46
47
    protected function getStore(array $config): StoreInterface
48
    {
49
        $adapter = $this->getFilesystemAdapter($config);
50
        $filesystem = new Filesystem($adapter);
51
        $store = new Flysystem($filesystem);
52
53
        return $store;
54
    }
55
}
56