Completed
Pull Request — master (#140)
by
unknown
05:29
created

Local::unlink()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
namespace phpbu\App\Backup\File;
3
4
use phpbu\App\Backup\File;
5
use SplFileInfo;
6
use phpbu\App\Exception;
7
8
/**
9
 * File
10
 *
11
 * @package    phpbu
12
 * @subpackage Backup
13
 * @author     Sebastian Feldmann <[email protected]>
14
 * @copyright  Sebastian Feldmann <[email protected]>
15
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
16
 * @link       http://phpbu.de/
17
 * @since      Class available since Release 1.0.0
18
 */
19
class Local implements File
20
{
21
    /**
22
     * FileInfo
23
     *
24
     * @var \SplFileInfo
25
     */
26
    protected $fileInfo;
27
28
    /**
29
     * Constructor
30
     *
31
     * @param SplFileInfo $fileInfo
32
     */
33
    public function __construct(SplFileInfo $fileInfo)
34
    {
35
        $this->fileInfo = $fileInfo;
36
    }
37
38
    /**
39
     * FileInfo getter.
40
     *
41
     * @return SplFileInfo
42
     */
43
    public function getFileInfo()
44
    {
45
        return $this->fileInfo;
46
    }
47
48
    /**
49
     * Return the filesize.
50
     *
51
     * @return integer
52
     */
53
    public function getSize(): int
54
    {
55
        return $this->fileInfo->getSize();
56
    }
57
58
    /**
59
     * Return the filename.
60
     *
61
     * @return string
62
     */
63
    public function getFilename(): string
64
    {
65
        return $this->fileInfo->getFilename();
66
    }
67
68
    /**
69
     * Return the full path and filename.
70
     *
71
     * @return string
72
     */
73
    public function getPathname(): string
74
    {
75
        return $this->fileInfo->getPathname();
76
    }
77
78
    /**
79
     * Return the path.
80
     *
81
     * @return string
82
     */
83
    public function getPath()
84
    {
85
        return $this->fileInfo->getPath();
86
    }
87
88
    /**
89
     * Return last modified date as unix timestamp.
90
     *
91
     * @return integer
92
     */
93
    public function getMTime(): int
94
    {
95
        return $this->fileInfo->getMTime();
96
    }
97
98
    /**
99
     * Return whether the file is writable or not.
100
     *
101
     * @return boolean
102
     */
103
    public function isWritable(): bool
104
    {
105
        return $this->fileInfo->isWritable();
106
    }
107
108
    /**
109
     * Deletes the file.
110
     *
111
     * @throws \phpbu\App\Exception
112
     */
113
    public function unlink()
114
    {
115
        $old = error_reporting(0);
116
        if (!unlink($this->fileInfo->getPathname())) {
117
            error_reporting($old);
118
            throw new Exception(sprintf('can\'t delete file: %s', $this->fileInfo->getPathname()));
119
        }
120
        error_reporting($old);
121
    }
122
}
123