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

AbstractTrashFolder   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 47
Duplicated Lines 48.94 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 23
loc 47
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getChildren() 12 12 2
A getChild() 11 11 3
A childExists() 0 8 2
A setName() 0 3 1
A createFile() 0 3 1
A createDirectory() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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