Completed
Push — master ( fb9cb6...dc5c4b )
by Morris
51:46 queued 21:25
created

VersionRoot::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 4
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_Versions\Sabre;
25
26
use OCP\Files\File;
27
use OCP\Files\IRootFolder;
28
use Sabre\DAV\Exception\Forbidden;
29
use Sabre\DAV\Exception\NotFound;
30
use Sabre\DAV\ICollection;
31
32
class VersionRoot implements ICollection {
33
34
	/** @var string */
35
	private $userId;
36
37
	/** @var IRootFolder */
38
	private $rootFolder;
39
40
	public function __construct(string $userId, IRootFolder $rootFolder) {
41
		$this->userId = $userId;
42
		$this->rootFolder = $rootFolder;
43
	}
44
45
	public function delete() {
46
		throw new Forbidden();
47
	}
48
49
	public function getName(): string {
50
		return 'versions';
51
	}
52
53
	public function setName($name) {
54
		throw new Forbidden();
55
	}
56
57
	public function createFile($name, $data = null) {
58
		throw new Forbidden();
59
	}
60
61
	public function createDirectory($name) {
62
		throw new Forbidden();
63
	}
64
65
	public function getChild($name) {
66
		$userFolder = $this->rootFolder->getUserFolder($this->userId);
67
68
		$fileId = (int)$name;
69
		$nodes = $userFolder->getById($fileId);
70
71
		if ($nodes === []) {
72
			throw new NotFound();
73
		}
74
75
		$node = array_pop($nodes);
76
77
		if (!$node instanceof File) {
78
			throw new NotFound();
79
		}
80
81
		return new VersionCollection($userFolder, $node, $this->userId);
82
	}
83
84
	public function getChildren(): array {
85
		return [];
86
	}
87
88
	public function childExists($name): bool {
89
		try {
90
			$this->getChild($name);
91
			return true;
92
		} catch (NotFound $e) {
0 ignored issues
show
Bug introduced by
The class Sabre\DAV\Exception\NotFound does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
93
			return false;
94
		}
95
	}
96
97
	public function getLastModified(): int {
98
		return 0;
99
	}
100
}
101