Completed
Push — master ( ff3e8c...ea9b1c )
by Lukas
13:22 queued 02:44
created

SimpleFolder::getFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright 2016 Roeland Jago Douma <[email protected]>
4
 *
5
 * @author Roeland Jago Douma <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
namespace OC\Files\SimpleFS;
24
25
use OCP\Files\File;
26
use OCP\Files\Folder;
27
use OCP\Files\Node;
28
use OCP\Files\NotFoundException;
29
use OCP\Files\SimpleFS\ISimpleFolder;
30
31
class SimpleFolder implements ISimpleFolder   {
32
33
	/** @var Folder */
34
	private $folder;
35
36
	/**
37
	 * Folder constructor.
38
	 *
39
	 * @param Folder $folder
40
	 */
41
	public function __construct(Folder $folder) {
42
		$this->folder = $folder;
43
	}
44
45
	public function getName() {
46
		return $this->folder->getName();
47
	}
48
49 View Code Duplication
	public function getDirectoryListing() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
		$listing = $this->folder->getDirectoryListing();
51
52
		$fileListing = array_map(function(Node $file) {
53
			if ($file instanceof File) {
54
				return new SimpleFile($file);
55
			}
56
			return null;
57
		}, $listing);
58
59
		$fileListing = array_filter($fileListing);
60
61
		return array_values($fileListing);
62
	}
63
64
	public function delete() {
65
		$this->folder->delete();
66
	}
67
68
	public function fileExists($name) {
69
		return $this->folder->nodeExists($name);
70
	}
71
72
	public function getFile($name) {
73
		$file = $this->folder->get($name);
74
75
		if (!($file instanceof File)) {
76
			throw new NotFoundException();
77
		}
78
79
		return new SimpleFile($file);
80
	}
81
82
	public function newFile($name) {
83
		$file = $this->folder->newFile($name);
84
85
		return new SimpleFile($file);
86
	}
87
}
88