Passed
Push — master ( 865ea9...f5a1ef )
by butschster
29:08 queued 21:20
created

ReadableTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 70
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getVisibility() 0 6 1
A getMimeType() 0 5 1
A exists() 0 5 1
A getContents() 0 5 1
A getStream() 0 5 1
A getSize() 0 5 1
A getLastModified() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Storage\Storage;
6
7
use JetBrains\PhpStorm\ExpectedValues;
8
use Psr\Http\Message\UriInterface;
9
use Spiral\Storage\Storage;
10
use Spiral\Storage\StorageInterface;
11
use Spiral\Storage\BucketInterface;
12
use Spiral\Storage\Visibility;
13
14
trait ReadableTrait
15
{
16
    /**
17
     * {@see StorageInterface::bucket()}
18
     */
19
    abstract public function bucket(string $name = null): BucketInterface;
20
21
    public function getContents(string|\Stringable $id): string
22
    {
23
        [$name, $pathname] = $this->parseUri($id);
24
25
        return $this->bucket($name)->getContents($pathname);
26
    }
27
28
    public function getStream(string|\Stringable $id)
29
    {
30
        [$name, $pathname] = $this->parseUri($id);
31
32
        return $this->bucket($name)->getStream($pathname);
33
    }
34
35
    public function exists(string|\Stringable $id): bool
36
    {
37
        [$name, $pathname] = $this->parseUri($id);
38
39
        return $this->bucket($name)->exists($pathname);
40
    }
41
42
    /**
43
     * @return positive-int|0
0 ignored issues
show
Documentation Bug introduced by
The doc comment positive-int|0 at position 0 could not be parsed: Unknown type name 'positive-int' at position 0 in positive-int|0.
Loading history...
44
     */
45
    public function getLastModified(string|\Stringable $id): int
46
    {
47
        [$name, $pathname] = $this->parseUri($id);
48
49
        return $this->bucket($name)->getLastModified($pathname);
50
    }
51
52
    /**
53
     * @return positive-int|0
0 ignored issues
show
Documentation Bug introduced by
The doc comment positive-int|0 at position 0 could not be parsed: Unknown type name 'positive-int' at position 0 in positive-int|0.
Loading history...
54
     */
55
    public function getSize(string|\Stringable $id): int
56
    {
57
        [$name, $pathname] = $this->parseUri($id);
58
59
        return $this->bucket($name)->getSize($pathname);
60
    }
61
62
    public function getMimeType(string|\Stringable $id): string
63
    {
64
        [$name, $pathname] = $this->parseUri($id);
65
66
        return $this->bucket($name)->getMimeType($pathname);
67
    }
68
69
    /**
70
     * @return Visibility::VISIBILITY_*
71
     */
72
    #[ExpectedValues(valuesFromClass: Visibility::class)]
73
    public function getVisibility(string|\Stringable $id): string
74
    {
75
        [$name, $pathname] = $this->parseUri($id);
76
77
        return $this->bucket($name)->getVisibility($pathname);
78
    }
79
80
    /**
81
     * {@see Storage::parseUri()}
82
     */
83
    abstract protected function parseUri(string|\Stringable $uri, bool $withScheme = true): array;
84
}
85