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

VersionCollection::getChild()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 12
rs 9.4285
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 OCA\Files_Versions\Storage;
27
use OCP\Files\File;
28
use OCP\Files\Folder;
29
use Sabre\DAV\Exception\Forbidden;
30
use Sabre\DAV\Exception\NotFound;
31
use Sabre\DAV\ICollection;
32
33
class VersionCollection implements ICollection {
34
	/** @var Folder */
35
	private $userFolder;
36
37
	/** @var File */
38
	private $file;
39
40
	/** @var string */
41
	private $userId;
42
43
	public function __construct(Folder $userFolder, File $file, string $userId) {
44
		$this->userFolder = $userFolder;
45
		$this->file = $file;
46
		$this->userId = $userId;
47
	}
48
49
	public function createFile($name, $data = null) {
50
		throw new Forbidden();
51
	}
52
53
	public function createDirectory($name) {
54
		throw new Forbidden();
55
	}
56
57
	public function getChild($name) {
58
		/** @var VersionFile[] $versions */
59
		$versions = $this->getChildren();
60
61
		foreach ($versions as $version) {
62
			if ($version->getName() === $name) {
0 ignored issues
show
Bug introduced by
Consider using $version->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
63
				return $version;
64
			}
65
		}
66
67
		throw new NotFound();
68
	}
69
70
	public function getChildren(): array {
71
		$versions = Storage::getVersions($this->userId, $this->userFolder->getRelativePath($this->file->getPath()));
72
73
		return array_map(function (array $data) {
74
			return new VersionFile($data, $this->userFolder->getParent());
75
		}, $versions);
76
	}
77
78
	public function childExists($name): bool {
79
		try {
80
			$this->getChild($name);
81
			return true;
82
		} 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...
83
			return false;
84
		}
85
	}
86
87
	public function delete() {
88
		throw new Forbidden();
89
	}
90
91
	public function getName(): string {
92
		return (string)$this->file->getId();
93
	}
94
95
	public function setName($name) {
96
		throw new Forbidden();
97
	}
98
99
	public function getLastModified(): int {
100
		return 0;
101
	}
102
}
103