LocalFilesystemFacadeDecorator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
c 2
b 0
f 1
nc 1
nop 3
dl 0
loc 5
rs 10
ccs 1
cts 1
cp 1
crap 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\Adapter\Local\Decorator;
15
16
use League\Flysystem\FilesystemOperator;
17
use Micro\Plugin\Filesystem\Adapter\Local\Configuration\FilesystemLocalAdapterPluginConfigurationInterface;
18
use Micro\Plugin\Filesystem\Business\FS\FsFactoryInterface;
19
use Micro\Plugin\Filesystem\Configuration\FilesystemPluginConfigurationInterface;
20
use Micro\Plugin\Filesystem\Facade\FilesystemFacadeInterface;
21
22
class LocalFilesystemFacadeDecorator implements FilesystemFacadeInterface
23
{
24
    /**
25
     * @param FilesystemFacadeInterface              $filesystemFacade
26
     * @param FsFactoryInterface                     $fsFactory
27
     * @param FilesystemPluginConfigurationInterface $pluginConfiguration
28
     */
29 2
    public function __construct(
30
        private readonly FilesystemFacadeInterface $filesystemFacade,
31
        private readonly FsFactoryInterface $fsFactory,
32
        private readonly FilesystemPluginConfigurationInterface $pluginConfiguration
33
    ) {
34 2
    }
35
36
    /**
37
     * @param string $adapterName
38
     *
39
     * @return FilesystemOperator
40
     */
41 2
    public function createFsOperator(string $adapterName = FilesystemPluginConfigurationInterface::ADAPTER_DEFAULT): FilesystemOperator
42
    {
43 2
        if (FilesystemLocalAdapterPluginConfigurationInterface::ADAPTER_NAME !== $this->pluginConfiguration->getAdapterType($adapterName)) {
44 1
            return $this->filesystemFacade->createFsOperator($adapterName);
45
        }
46
47 1
        return $this->fsFactory->create($adapterName);
48
    }
49
}
50