Completed
Push — master ( 412925...57ea46 )
by Morris
18:29 queued 10s
created

TrashFolderFile::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 4
rs 9.6666
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright 2018, Roeland Jago Douma <[email protected]>
5
 *
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
namespace OCA\Files_Trashbin\Sabre;
25
26
use OCP\Files\FileInfo;
27
use Sabre\DAV\Exception\Forbidden;
28
use Sabre\DAV\IFile;
29
30
class TrashFolderFile implements IFile, ITrash {
31
	/** @var string */
32
	private $root;
33
34
	/** @var string */
35
	private $userId;
36
37
	/** @var FileInfo */
38
	private $data;
39
40
	/** @var string */
41
	private $location;
42
43 View Code Duplication
	public function __construct(string $root,
44
								string $userId,
45
								FileInfo $data,
46
								string $location) {
47
		$this->root = $root;
48
		$this->userId = $userId;
49
		$this->data = $data;
50
		$this->location = $location;
51
	}
52
53
	public function put($data) {
54
		throw new Forbidden();
55
	}
56
57
	public function get() {
58
		return $this->data->getStorage()->fopen($this->data->getInternalPath(), 'rb');
59
	}
60
61
	public function getContentType(): string {
62
		return $this->data->getMimetype();
63
	}
64
65
	public function getETag(): string {
66
		return $this->data->getEtag();
67
	}
68
69
	public function getSize(): int {
70
		return $this->data->getSize();
71
	}
72
73
	public function delete() {
74
		\OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null);
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
75
	}
76
77
	public function getName(): string {
78
		return $this->data->getName();
79
	}
80
81
	public function setName($name) {
82
		throw new Forbidden();
83
	}
84
85
	public function getLastModified(): int {
86
		return $this->data->getMtime();
87
	}
88
89
	public function restore(): bool {
90
		return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null);
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
91
	}
92
93
	public function getFilename(): string {
94
		return $this->data->getName();
95
	}
96
97
	public function getOriginalLocation(): string {
98
		return $this->location . '/' . $this->getFilename();
99
	}
100
101
	public function getDeletionTime(): int {
102
		return $this->getLastModified();
103
	}
104
}
105