Completed
Push — master ( 3e5138...d2cc48 )
by Morris
22:18
created

TrashFile   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 70
c 0
b 0
f 0
rs 10
wmc 15
lcom 1
cbo 3

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A put() 0 3 1
A get() 0 3 1
A getContentType() 0 3 1
A getETag() 0 3 1
A getSize() 0 3 1
A delete() 0 3 1
A getName() 0 3 1
A setName() 0 3 1
A getLastModified() 0 3 1
A restore() 0 3 1
A getFilename() 0 3 1
A getOriginalLocation() 0 3 1
A getDeletionTime() 0 3 1
A getFileId() 0 3 1
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 TrashFile implements IFile, ITrash {
31
	/** @var string */
32
	private $userId;
33
34
	/** @var FileInfo */
35
	private $data;
36
37
	public function __construct(string $userId, FileInfo $data) {
38
		$this->userId = $userId;
39
		$this->data = $data;
40
	}
41
42
	public function put($data) {
43
		throw new Forbidden();
44
	}
45
46
	public function get() {
47
		return $this->data->getStorage()->fopen($this->data->getInternalPath().'.d'.$this->getLastModified(), 'rb');
48
	}
49
50
	public function getContentType(): string {
51
		return $this->data->getMimetype();
52
	}
53
54
	public function getETag(): string	 {
55
		return $this->data->getEtag();
56
	}
57
58
	public function getSize(): int {
59
		return $this->data->getSize();
60
	}
61
62
	public function delete() {
63
		\OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified());
64
	}
65
66
	public function getName(): string {
67
		return $this->data->getName() . '.d' . $this->getLastModified();
68
	}
69
70
	public function setName($name) {
71
		throw new Forbidden();
72
	}
73
74
	public function getLastModified(): int {
75
		return $this->data->getMtime();
76
	}
77
78
	public function restore(): bool {
79
		return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
80
	}
81
82
	public function getFilename(): string {
83
		return $this->data->getName();
84
	}
85
86
	public function getOriginalLocation(): string {
87
		return $this->data['extraData'];
88
	}
89
90
	public function getDeletionTime(): int {
91
		return $this->getLastModified();
92
	}
93
94
	public function getFileId(): int {
95
		return $this->data->getId();
96
	}
97
98
99
}
100