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

WritableTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 8
dl 0
loc 44
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setVisibility() 0 5 1
A create() 0 3 1
A write() 0 3 1
A copy() 0 3 1
A move() 0 3 1
A delete() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Storage\File;
6
7
use JetBrains\PhpStorm\ExpectedValues;
8
use Spiral\Storage\FileInterface;
9
use Spiral\Storage\BucketInterface;
10
use Spiral\Storage\Visibility;
11
12
/**
13
 * @mixin WritableInterface
14
 */
15
trait WritableTrait
16
{
17
    /**
18
     * {@see EntryInterface::getPathname()}
19
     */
20
    abstract public function getPathname(): string;
21
22
    /**
23
     * {@see EntryInterface::getBucket()}
24
     */
25
    abstract public function getBucket(): BucketInterface;
26
27
    public function create(array $config = []): FileInterface
28
    {
29
        return $this->getBucket()->create($this->getPathname(), $config);
30
    }
31
32
    public function write(mixed $content, array $config = []): FileInterface
33
    {
34
        return $this->getBucket()->write($this->getPathname(), $content, $config);
35
    }
36
37
    public function setVisibility(
38
        #[ExpectedValues(valuesFromClass: Visibility::class)]
39
        string $visibility
40
    ): FileInterface {
41
        return $this->getBucket()->setVisibility($this->getPathname(), $visibility);
42
    }
43
44
    public function copy(string $pathname, BucketInterface $storage = null, array $config = []): FileInterface
45
    {
46
        return $this->getBucket()->copy($this->getPathname(), $pathname, $storage, $config);
47
    }
48
49
    public function move(string $pathname, BucketInterface $storage = null, array $config = []): FileInterface
50
    {
51
        return $this->getBucket()->move($this->getPathname(), $pathname, $storage, $config);
52
    }
53
54
    public function delete(bool $clean = false): void
55
    {
56
        $source = $this->getBucket();
57
58
        $source->delete($this->getPathname(), $clean);
59
    }
60
}
61