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

File::getPathname()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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;
13
14
use Spiral\Distribution\UriResolverInterface;
15
use Spiral\Storage\File\ReadableTrait;
16
use Spiral\Storage\File\UriResolvableTrait;
17
use Spiral\Storage\File\WritableTrait;
18
19
final class File implements FileInterface
20
{
21
    use UriResolvableTrait;
22
    use ReadableTrait;
23
    use WritableTrait;
24
25
    /**
26
     * @var BucketInterface
27
     */
28
    private $storage;
29
30
    /**
31
     * @var string
32
     */
33
    private $pathname;
34
35
    /**
36
     * @var UriResolverInterface|null
37
     */
38
    private $resolver;
39
40
    /**
41
     * @param BucketInterface $storage
42
     * @param string $pathname
43
     * @param UriResolverInterface|null $resolver
44
     */
45
    public function __construct(BucketInterface $storage, string $pathname, UriResolverInterface $resolver = null)
46
    {
47
        $this->storage = $storage;
48
        $this->pathname = $pathname;
49
        $this->resolver = $resolver;
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function __toString(): string
56
    {
57
        return $this->getId();
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getId(): string
64
    {
65
        $name = $this->storage->getName();
66
67
        if ($name === null) {
68
            return $this->getPathname();
69
        }
70
71
        return \sprintf('%s://%s', $name, $this->getPathname());
72
    }
73
74
    /**
75
     * {@inheritDoc}
76
     */
77
    public function getPathname(): string
78
    {
79
        return $this->pathname;
80
    }
81
82
    /**
83
     * {@inheritDoc}
84
     */
85
    public function getBucket(): BucketInterface
86
    {
87
        return $this->storage;
88
    }
89
90
    /**
91
     * @return UriResolverInterface|null
92
     */
93
    protected function getResolver(): ?UriResolverInterface
94
    {
95
        return $this->resolver;
96
    }
97
}
98