Passed
Push — master ( 4c60ff...437d93 )
by Julius
15:25 queued 12s
created

NullCache   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 104
rs 10
c 0
b 0
f 0
wmc 24

23 Methods

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