Passed
Push — master ( 7a09b7...f1e2fb )
by Robin
14:09 queued 14s
created

NullCache::getStatus()   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\Cache\ICacheEntry;
30
use OCP\Files\FileInfo;
31
use OCP\Files\Search\ISearchQuery;
32
33
class NullCache implements ICache {
34
	public function getNumericStorageId() {
35
		return -1;
36
	}
37
38
	public function get($file) {
39
		return $file !== '' ? null :
40
			new CacheEntry([
41
				'fileid' => -1,
42
				'parent' => -1,
43
				'name' => '',
44
				'path' => '',
45
				'size' => '0',
46
				'mtime' => time(),
47
				'storage_mtime' => time(),
48
				'etag' => '',
49
				'mimetype' => FileInfo::MIMETYPE_FOLDER,
50
				'mimepart' => 'httpd',
51
				'permissions' => Constants::PERMISSION_READ
52
			]);
53
	}
54
55
	public function getFolderContents($folder) {
56
		return [];
57
	}
58
59
	public function getFolderContentsById($fileId) {
60
		return [];
61
	}
62
63
	public function put($file, array $data) {
64
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
65
	}
66
67
	public function insert($file, array $data) {
68
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
69
	}
70
71
	public function update($id, array $data) {
72
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
73
	}
74
75
	public function getId($file) {
76
		return -1;
77
	}
78
79
	public function getParentId($file) {
80
		return -1;
81
	}
82
83
	public function inCache($file) {
84
		return $file === '';
85
	}
86
87
	public function remove($file) {
88
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
89
	}
90
91
	public function move($source, $target) {
92
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
93
	}
94
95
	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
96
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
97
	}
98
99
	public function getStatus($file) {
100
		return ICache::COMPLETE;
101
	}
102
103
	public function search($pattern) {
104
		return [];
105
	}
106
107
	public function searchByMime($mimetype) {
108
		return [];
109
	}
110
111
	public function searchQuery(ISearchQuery $query) {
112
		return [];
113
	}
114
115
	public function getIncomplete() {
116
		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...
117
	}
118
119
	public function getPathById($id) {
120
		return '';
121
	}
122
123
	public function normalize($path) {
124
		return $path;
125
	}
126
127
	public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {
128
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
129
	}
130
}
131