LocalFilesystemFacadeDecorator::createFsOperator()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
ccs 4
cts 4
cp 1
crap 2
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