Completed
Push — master ( f62f21...f72c97 )
by Freek
05:09
created

Backup::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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 \Spatie\Backup\BackupDestination\Disk */
11
    protected $disk;
12
13
    /** @var string */
14
    protected $path;
15
16
    /**
17
     * @param \Illuminate\Contracts\Filesystem\Filesystem $disk
18
     * @param string                                      $path
19
     */
20
    public function __construct(Filesystem $disk, $path)
21
    {
22
        $this->disk = $disk;
0 ignored issues
show
Documentation Bug introduced by
It seems like $disk of type object<Illuminate\Contra...\Filesystem\Filesystem> is incompatible with the declared type object<Spatie\Backup\BackupDestination\Disk> of property $disk.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
        $this->path = $path;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function path()
30
    {
31
        return $this->path;
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    public function exists()
38
    {
39
        return $this->disk->exists($this->path);
40
    }
41
42
    /**
43
     * @return \Carbon\Carbon
44
     */
45
    public function date()
46
    {
47
        return Carbon::createFromTimestamp($this->disk->lastModified($this->path));
48
    }
49
50
    /**
51
     * Get the size in bytes.
52
     *
53
     * @return int
54
     */
55
    public function size()
56
    {
57
        if (!$this->exists()) {
58
            return 0;
59
        }
60
61
        return $this->disk->size($this->path);
62
    }
63
64
    /**
65
     * Delete the backup from the disk.
66
     */
67
    public function delete()
68
    {
69
        $this->disk->delete($this->path);
70
        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...
71
    }
72
}
73