Passed
Pull Request — master (#407)
by Kirill
11:08 queued 03:58
created

LocalBuilder::buildAdvanced()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.8666
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Storage\Builder\Adapter;
13
14
use League\Flysystem\FilesystemAdapter;
15
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
16
use Spiral\Storage\Config\DTO\FileSystemInfo\LocalInfo;
17
use Spiral\Storage\Config\DTO\FileSystemInfo\FileSystemInfoInterface;
18
19
/**
20
 * @property FileSystemInfoInterface|LocalInfo $fsInfo
21
 */
22
class LocalBuilder extends AbstractBuilder
23
{
24
    protected const FILE_SYSTEM_INFO_CLASS = LocalInfo::class;
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function buildSimple(): FilesystemAdapter
30
    {
31
        $adapterClass = $this->fsInfo->getAdapterClass();
32
33
        return new $adapterClass(
34
            $this->fsInfo->getOption(LocalInfo::ROOT_DIR_KEY)
0 ignored issues
show
Bug introduced by
The method getOption() does not exist on Spiral\Storage\Config\DT...FileSystemInfoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Spiral\Storage\Config\DT...FileSystemInfoInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
            $this->fsInfo->/** @scrutinizer ignore-call */ 
35
                           getOption(LocalInfo::ROOT_DIR_KEY)
Loading history...
35
        );
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function buildAdvanced(): FilesystemAdapter
42
    {
43
        $adapterClass = $this->fsInfo->getAdapterClass();
44
45
        return new $adapterClass(
46
            $this->fsInfo->getOption(LocalInfo::ROOT_DIR_KEY),
47
            $this->fsInfo->hasOption(LocalInfo::VISIBILITY_KEY)
0 ignored issues
show
Bug introduced by
The method hasOption() does not exist on Spiral\Storage\Config\DT...FileSystemInfoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Spiral\Storage\Config\DT...FileSystemInfoInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
            $this->fsInfo->/** @scrutinizer ignore-call */ 
48
                           hasOption(LocalInfo::VISIBILITY_KEY)
Loading history...
48
                ? PortableVisibilityConverter::fromArray($this->fsInfo->getOption(LocalInfo::VISIBILITY_KEY))
0 ignored issues
show
Bug introduced by
It seems like $this->fsInfo->getOption...alInfo::VISIBILITY_KEY) can also be of type null; however, parameter $permissionMap of League\Flysystem\UnixVis...yConverter::fromArray() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
                ? PortableVisibilityConverter::fromArray(/** @scrutinizer ignore-type */ $this->fsInfo->getOption(LocalInfo::VISIBILITY_KEY))
Loading history...
49
                : null,
50
            $this->fsInfo->hasOption(LocalInfo::WRITE_FLAGS_KEY)
51
                ? $this->fsInfo->getOption(LocalInfo::WRITE_FLAGS_KEY)
52
                : \LOCK_EX,
53
            $this->fsInfo->hasOption(LocalInfo::LINK_HANDLING_KEY)
54
                ? $this->fsInfo->getOption(LocalInfo::LINK_HANDLING_KEY)
55
                : $adapterClass::DISALLOW_LINKS
56
        );
57
    }
58
}
59