Passed
Push — master ( 323f40...cdc43c )
by Roeland
13:28 queued 10s
created

NullCache::inCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, Robin Appelman <[email protected]>
4
 *
5
 * @author Robin Appelman <[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
24
namespace OC\Lockdown\Filesystem;
25
26
use OC\Files\Cache\CacheEntry;
27
use OCP\Constants;
28
use OCP\Files\Cache\ICache;
29
use OCP\Files\FileInfo;
30
use OCP\Files\Search\ISearchQuery;
31
32
class NullCache implements ICache {
33
	public function getNumericStorageId() {
34
		return -1;
35
	}
36
37
	public function get($file) {
38
		return $file !== '' ? null :
39
			new CacheEntry([
40
				'fileid' => -1,
41
				'parent' => -1,
42
				'name' => '',
43
				'path' => '',
44
				'size' => '0',
45
				'mtime' => time(),
46
				'storage_mtime' => time(),
47
				'etag' => '',
48
				'mimetype' => FileInfo::MIMETYPE_FOLDER,
49
				'mimepart' => 'httpd',
50
				'permissions' => Constants::PERMISSION_READ
51
			]);
52
	}
53
54
	public function getFolderContents($folder) {
55
		return [];
56
	}
57
58
	public function getFolderContentsById($fileId) {
59
		return [];
60
	}
61
62
	public function put($file, array $data) {
63
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
64
	}
65
66
	public function insert($file, array $data) {
67
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
68
	}
69
70
	public function update($id, array $data) {
71
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
72
	}
73
74
	public function getId($file) {
75
		return -1;
76
	}
77
78
	public function getParentId($file) {
79
		return -1;
80
	}
81
82
	public function inCache($file) {
83
		return $file === '';
84
	}
85
86
	public function remove($file) {
87
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
88
	}
89
90
	public function move($source, $target) {
91
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
92
	}
93
94
	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
95
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
96
	}
97
98
	public function getStatus($file) {
99
		return ICache::COMPLETE;
100
	}
101
102
	public function search($pattern) {
103
		return [];
104
	}
105
106
	public function searchByMime($mimetype) {
107
		return [];
108
	}
109
110
	public function searchQuery(ISearchQuery $query) {
111
		return [];
112
	}
113
114
	public function getIncomplete() {
115
		return [];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array() returns the type array which is incompatible with the return type mandated by OCP\Files\Cache\ICache::getIncomplete() of boolean|string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
116
	}
117
118
	public function getPathById($id) {
119
		return '';
120
	}
121
122
	public function normalize($path) {
123
		return $path;
124
	}
125
126
}
127