Passed
Pull Request — master (#407)
by Kirill
05:29
created

LocalFsBuilderTrait::buildLocalFs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Tests\Storage\Traits;
6
7
use League\Flysystem\Filesystem;
8
use League\Flysystem\FilesystemAdapter;
9
use League\Flysystem\Local\LocalFilesystemAdapter;
10
use Spiral\Storage\Builder\AdapterFactory;
11
use Spiral\Storage\Config\DTO\FileSystemInfo\LocalInfo;
12
use Spiral\Storage\Exception\StorageException;
13
14
trait LocalFsBuilderTrait
15
{
16
    /**
17
     * @param bool|null $useVcsPrefix
18
     *
19
     * @return Filesystem
20
     *
21
     * @throws StorageException
22
     */
23
    protected function buildLocalFs(?bool $useVcsPrefix = false): Filesystem
24
    {
25
        return new Filesystem(
26
            $this->buildLocalAdapter($useVcsPrefix)
27
        );
28
    }
29
30
    /**
31
     * @param bool|null $useVcsPrefix
32
     *
33
     * @return LocalFilesystemAdapter
34
     *
35
     * @throws StorageException
36
     */
37
    protected function buildLocalAdapter(?bool $useVcsPrefix = false): FilesystemAdapter
38
    {
39
        return AdapterFactory::build($this->buildLocalInfo(self::SERVER_NAME, $useVcsPrefix));
0 ignored issues
show
Bug introduced by
The constant Spiral\Tests\Storage\Tra...ilderTrait::SERVER_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
40
    }
41
42
    /**
43
     * @param string|null $name
44
     * @param bool|null $useVcsPrefix
45
     *
46
     * @return LocalInfo
47
     *
48
     * @throws StorageException
49
     */
50
    protected function buildLocalInfo(
51
        ?string $name = self::SERVER_NAME,
0 ignored issues
show
Bug introduced by
The constant Spiral\Tests\Storage\Tra...ilderTrait::SERVER_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
52
        ?bool $useVcsPrefix = false
53
    ): LocalInfo {
54
        return new LocalInfo($name, $this->buildLocalInfoDescription($useVcsPrefix));
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type null; however, parameter $name of Spiral\Storage\Config\DT...ocalInfo::__construct() does only seem to accept string, 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

54
        return new LocalInfo(/** @scrutinizer ignore-type */ $name, $this->buildLocalInfoDescription($useVcsPrefix));
Loading history...
55
    }
56
57
    protected function buildLocalInfoDescription(?bool $useVcsPrefix = false): array
58
    {
59
        $prefix = $useVcsPrefix ? self::VFS_PREFIX : '';
0 ignored issues
show
Bug introduced by
The constant Spiral\Tests\Storage\Tra...uilderTrait::VFS_PREFIX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
60
61
        return [
62
            LocalInfo::ADAPTER_KEY => LocalFilesystemAdapter::class,
63
            LocalInfo::OPTIONS_KEY => [
64
                LocalInfo::ROOT_DIR_KEY => $prefix . self::ROOT_DIR,
0 ignored issues
show
Bug introduced by
The constant Spiral\Tests\Storage\Tra...sBuilderTrait::ROOT_DIR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
65
                LocalInfo::HOST_KEY => self::CONFIG_HOST,
0 ignored issues
show
Bug introduced by
The constant Spiral\Tests\Storage\Tra...ilderTrait::CONFIG_HOST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
66
            ],
67
        ];
68
    }
69
}
70