Completed
Push — master ( c8eb31...5a1d8c )
by Freek
02:00
created

Backup::stream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Backup\BackupDestination;
4
5
use Carbon\Carbon;
6
use Illuminate\Contracts\Filesystem\Filesystem;
7
8
class Backup
9
{
10
    /** @var \Illuminate\Contracts\Filesystem\Filesystem */
11
    protected $disk;
12
13
    /** @var string */
14
    protected $path;
15
16
    public function __construct(Filesystem $disk, string $path)
17
    {
18
        $this->disk = $disk;
19
20
        $this->path = $path;
21
    }
22
23
    public function path(): string
24
    {
25
        return $this->path;
26
    }
27
28
    public function exists(): bool
29
    {
30
        return $this->disk->exists($this->path);
31
    }
32
33
    public function date(): Carbon
34
    {
35
        return Carbon::createFromTimestamp($this->disk->lastModified($this->path));
36
    }
37
38
    /**
39
     * Get the size in bytes.
40
     */
41
    public function size(): int
42
    {
43
        if (! $this->exists()) {
44
            return 0;
45
        }
46
47
        return $this->disk->size($this->path);
48
    }
49
50
    public function stream()
51
    {
52
        return $this->disk->readStream($this->path);
0 ignored issues
show
Bug introduced by
The method readStream() does not seem to exist on object<Illuminate\Contra...\Filesystem\Filesystem>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
    }
54
55
    public function delete()
56
    {
57
        $this->disk->delete($this->path);
58
59
        consoleOutput()->info("Deleted backup `{$this->path}`.");
0 ignored issues
show
Documentation Bug introduced by
The method info does not exist on object<Spatie\Backup\Helpers\ConsoleOutput>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
60
    }
61
}
62