Completed
Push — master ( e0f925...4ad272 )
by Morris
84:55 queued 70:47
created

AbstractTrashFolder::getChildren()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 0
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2018 Robin Appelman <[email protected]>
5
 *
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OCA\Files_Trashbin\Sabre;
24
25
use OCA\Files_Trashbin\Trash\ITrashItem;
26
use OCP\Files\FileInfo;
27
use Sabre\DAV\Exception\Forbidden;
28
use Sabre\DAV\Exception\NotFound;
29
use Sabre\DAV\ICollection;
30
31
abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash {
32 View Code Duplication
	public function getChildren(): array {
33
		$entries = $this->trashManager->listTrashFolder($this->data);
34
35
		$children = array_map(function (ITrashItem $entry) {
36
			if ($entry->getType() === FileInfo::TYPE_FOLDER) {
37
				return new TrashFolderFolder($this->trashManager, $entry);
38
			}
39
			return new TrashFolderFile($this->trashManager, $entry);
40
		}, $entries);
41
42
		return $children;
43
	}
44
45 View Code Duplication
	public function getChild($name): ITrash {
46
		$entries = $this->getChildren();
47
48
		foreach ($entries as $entry) {
49
			if ($entry->getName() === $name) {
50
				return $entry;
51
			}
52
		}
53
54
		throw new NotFound();
55
	}
56
57
	public function childExists($name): bool {
58
		try {
59
			$this->getChild($name);
60
			return true;
61
		} 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...
62
			return false;
63
		}
64
	}
65
66
	public function setName($name) {
67
		throw new Forbidden();
68
	}
69
70
	public function createFile($name, $data = null) {
71
		throw new Forbidden();
72
	}
73
74
	public function createDirectory($name) {
75
		throw new Forbidden();
76
	}
77
}
78