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

LocalSystemResolver::buildUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
rs 10
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\Resolver;
13
14
use Spiral\Storage\Config\DTO\FileSystemInfo\LocalInfo;
15
use Spiral\Storage\Config\DTO\FileSystemInfo\FileSystemInfoInterface;
16
use Spiral\Storage\Exception\ResolveException;
17
18
class LocalSystemResolver extends AbstractAdapterResolver
19
{
20
    protected const FILE_SYSTEM_INFO_CLASS = LocalInfo::class;
21
22
    /**
23
     * @var FileSystemInfoInterface|LocalInfo
24
     */
25
    protected $fsInfo;
26
27
    /**
28
     * @param string $uri
29
     * @param array $options
30
     *
31
     * @return string
32
     *
33
     * @throws ResolveException
34
     */
35
    public function buildUrl(string $uri, array $options = [])
36
    {
37
        if (!$this->fsInfo->hasOption(LocalInfo::HOST_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

37
        if (!$this->fsInfo->/** @scrutinizer ignore-call */ hasOption(LocalInfo::HOST_KEY)) {
Loading history...
38
            throw new ResolveException(
39
                \sprintf('Url can\'t be built for filesystem `%s` - host was not defined', $this->fsInfo->getName())
40
            );
41
        }
42
43
        return \sprintf(
44
            '%s%s',
45
            $this->fsInfo->getOption(LocalInfo::HOST_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

45
            $this->fsInfo->/** @scrutinizer ignore-call */ 
46
                           getOption(LocalInfo::HOST_KEY),
Loading history...
46
            $this->normalizeFilePath($uri)
47
        );
48
    }
49
}
50