FsFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 27
rs 10
ccs 10
cts 10
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 12 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Filesystem\Business\FS;
15
16
use League\Flysystem\Filesystem;
17
use League\Flysystem\FilesystemOperator;
18
use Micro\Plugin\Filesystem\Business\Adapter\AdapterFactoryInterface;
19
use Micro\Plugin\Filesystem\Configuration\FilesystemPluginConfigurationInterface;
20
21
/**
22
 * @author Stanislau Komar <[email protected]>
23
 */
24
class FsFactory implements FsFactoryInterface
25
{
26
    /**
27
     * @param FilesystemPluginConfigurationInterface $pluginConfiguration
28
     * @param AdapterFactoryInterface                $adapterFactory
29
     */
30 1
    public function __construct(
31
        private readonly FilesystemPluginConfigurationInterface $pluginConfiguration,
32
        private readonly AdapterFactoryInterface $adapterFactory
33
    ) {
34 1
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39 1
    public function create($adapterName): FilesystemOperator
40
    {
41 1
        $adapterConfiguration = $this->pluginConfiguration->getAdapterConfiguration($adapterName);
42 1
        $adapter = $this->adapterFactory->create($adapterConfiguration);
43
44 1
        $options = [];
45 1
        $publicUrl = $adapterConfiguration->getPublicUrl();
46 1
        if ($publicUrl) {
47 1
            $options['public_url'] = $publicUrl;
48
        }
49
50 1
        return new Filesystem($adapter, $options);
51
    }
52
}
53