Completed
Push — master ( a23d52...d867f9 )
by Morris
48:45 queued 13s
created

TrashFolder::getDeletionTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Exception\NotFound;
29
use Sabre\DAV\ICollection;
30
31
class TrashFolder extends AbstractTrash implements ICollection, ITrash {
32
	/** @var string */
33
	private $userId;
34
35
	public function __construct(string $root, string $userId, FileInfo $data) {
36
		$this->userId = $userId;
37
		parent::__construct($data);
38
	}
39
40
	public function createFile($name, $data = null) {
41
		throw new Forbidden();
42
	}
43
44
	public function createDirectory($name) {
45
		throw new Forbidden();
46
	}
47
48
	public function getChild($name): ITrash {
49
		$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId);
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
50
51
		foreach ($entries as $entry) {
52
			if ($entry->getName() === $name) {
53 View Code Duplication
				if ($entry->getType() === FileInfo::TYPE_FOLDER) {
54
					return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
55
				}
56
				return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
57
			}
58
		}
59
60
		throw new NotFound();
61
	}
62
63
	public function getChildren(): array {
64
		$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId);
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
65
66
		$children = array_map(function (FileInfo $entry) {
67 View Code Duplication
			if ($entry->getType() === FileInfo::TYPE_FOLDER) {
68
				return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
69
			}
70
			return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
71
		}, $entries);
72
73
		return $children;
74
	}
75
76
	public function childExists($name): bool {
77
		$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId);
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
78
79
		foreach ($entries as $entry) {
80
			if ($entry->getName() === $name) {
81
				return true;
82
			}
83
		}
84
85
		return false;
86
	}
87
88
	public function delete() {
89
		\OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified());
90
	}
91
92
	public function getName(): string {
93
		return $this->data->getName() . '.d' . $this->getLastModified();
94
	}
95
96
	public function setName($name) {
97
		throw new Forbidden();
98
	}
99
100
	public function restore(): bool {
101
		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...
102
	}
103
104
	public function getOriginalLocation(): string {
105
		return $this->data['extraData'];
106
	}
107
}
108