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

WritableTrait::move()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
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\File;
13
14
use JetBrains\PhpStorm\ExpectedValues;
15
use Spiral\Storage\FileInterface;
16
use Spiral\Storage\StorageInterface;
17
use Spiral\Storage\Visibility;
18
19
/**
20
 * @mixin WritableInterface
21
 */
22
trait WritableTrait
23
{
24
    /**
25
     * {@see EntryInterface::getPathname()}
26
     */
27
    abstract public function getPathname(): string;
28
29
    /**
30
     * {@see EntryInterface::getStorage()}
31
     */
32
    abstract public function getStorage(): StorageInterface;
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function create(array $config = []): FileInterface
38
    {
39
        if (!$this->exists()) {
0 ignored issues
show
Bug introduced by
It seems like exists() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        if (!$this->/** @scrutinizer ignore-call */ exists()) {
Loading history...
40
            return $this->write('', $config);
41
        }
42
43
        return $this;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function write($content, array $config = []): FileInterface
50
    {
51
        $storage = $this->getStorage();
52
53
        return $storage->write($this->getPathname(), $content, $config);
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59
    public function setVisibility(
60
        #[ExpectedValues(valuesFromClass: Visibility::class)]
61
        string $visibility
62
    ): FileInterface {
63
        $storage = $this->getStorage();
64
65
        return $storage->setVisibility($this->getPathname(), $visibility);
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71
    public function copy(string $pathname, StorageInterface $storage = null, array $config = []): FileInterface
72
    {
73
        $source = $this->getStorage();
74
75
        return $source->copy($this->getPathname(), $pathname, $storage, $config);
76
    }
77
78
    /**
79
     * {@inheritDoc}
80
     */
81
    public function move(string $pathname, StorageInterface $storage = null, array $config = []): FileInterface
82
    {
83
        $source = $this->getStorage();
84
85
        return $source->move($this->getPathname(), $pathname, $storage, $config);
86
    }
87
88
    /**
89
     * {@inheritDoc}
90
     */
91
    public function delete(bool $clean = false): void
92
    {
93
        $source = $this->getStorage();
94
95
        $source->delete($this->getPathname(), $clean);
96
    }
97
}
98