Passed
Pull Request — master (#407)
by Kirill
06:41 queued 01:48
created

ReadableTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 96
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getLastModified() 0 7 1
A getMimeType() 0 7 1
A exists() 0 7 1
A getVisibility() 0 8 1
A getContents() 0 7 1
A getSize() 0 7 1
A getStream() 0 7 1
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\Manager;
13
14
use JetBrains\PhpStorm\ExpectedValues;
15
use Spiral\Storage\Exception\InvalidArgumentException;
16
use Spiral\Storage\Manager;
17
use Spiral\Storage\ManagerInterface;
18
use Spiral\Storage\StorageInterface;
19
use Spiral\Storage\Visibility;
20
21
/**
22
 * @mixin ReadableInterface
23
 * @psalm-import-type UriType from ReadableInterface
24
 */
25
trait ReadableTrait
26
{
27
    /**
28
     * {@see ManagerInterface::storage()}
29
     */
30
    abstract public function storage(string $name = null): StorageInterface;
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    public function getContents($uri): string
36
    {
37
        [$name, $pathname] = $this->parseUri($uri);
38
39
        $storage = $this->storage($name);
40
41
        return $storage->getContents($pathname);
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function getStream($uri)
48
    {
49
        [$name, $pathname] = $this->parseUri($uri);
50
51
        $storage = $this->storage($name);
52
53
        return $storage->getStream($pathname);
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59
    public function exists($uri): bool
60
    {
61
        [$name, $pathname] = $this->parseUri($uri);
62
63
        $storage = $this->storage($name);
64
65
        return $storage->exists($pathname);
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71
    public function getLastModified($uri): int
72
    {
73
        [$name, $pathname] = $this->parseUri($uri);
74
75
        $storage = $this->storage($name);
76
77
        return $storage->getLastModified($pathname);
78
    }
79
80
    /**
81
     * {@inheritDoc}
82
     */
83
    public function getSize($uri): int
84
    {
85
        [$name, $pathname] = $this->parseUri($uri);
86
87
        $storage = $this->storage($name);
88
89
        return $storage->getSize($pathname);
90
    }
91
92
    /**
93
     * {@inheritDoc}
94
     */
95
    public function getMimeType($uri): string
96
    {
97
        [$name, $pathname] = $this->parseUri($uri);
98
99
        $storage = $this->storage($name);
100
101
        return $storage->getMimeType($pathname);
102
    }
103
104
    /**
105
     * {@inheritDoc}
106
     */
107
    #[ExpectedValues(valuesFromClass: Visibility::class)]
108
    public function getVisibility($uri): string
109
    {
110
        [$name, $pathname] = $this->parseUri($uri);
111
112
        $storage = $this->storage($name);
113
114
        return $storage->getVisibility($pathname);
115
    }
116
117
    /**
118
     * {@see Manager::parseUri()}
119
     */
120
    abstract protected function parseUri($uri, bool $withScheme = true): array;
121
}
122