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

FailedCache::getPathById()   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, ownCloud, Inc.
4
 *
5
 * @author Robin Appelman <[email protected]>
6
 *
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
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, version 3,
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OC\Files\Cache;
24
25
use OCP\Constants;
26
use OCP\Files\Cache\ICache;
27
use OCP\Files\Cache\ICacheEntry;
28
use OCP\Files\Search\ISearchQuery;
29
30
/**
31
 * Storage placeholder to represent a missing precondition, storage unavailable
32
 */
33
class FailedCache implements ICache {
34
	/** @var bool whether to show the failed storage in the ui */
35
	private $visible;
36
37
	/**
38
	 * FailedCache constructor.
39
	 *
40
	 * @param bool $visible
41
	 */
42
	public function __construct($visible = true) {
43
		$this->visible = $visible;
44
	}
45
46
47
	public function getNumericStorageId() {
48
		return -1;
49
	}
50
51
	public function get($file) {
52
		if ($file === '') {
53
			return new CacheEntry([
54
				'fileid' => -1,
55
				'size' => 0,
56
				'mimetype' => 'httpd/unix-directory',
57
				'mimepart' => 'httpd',
58
				'permissions' => $this->visible ? Constants::PERMISSION_READ : 0,
59
				'mtime' => time()
60
			]);
61
		} else {
62
			return false;
63
		}
64
	}
65
66
	public function getFolderContents($folder) {
67
		return [];
68
	}
69
70
	public function getFolderContentsById($fileId) {
71
		return [];
72
	}
73
74
	public function put($file, array $data) {
75
	}
76
77
	public function insert($file, array $data) {
78
	}
79
80
	public function update($id, array $data) {
81
	}
82
83
	public function getId($file) {
84
		return -1;
85
	}
86
87
	public function getParentId($file) {
88
		return -1;
89
	}
90
91
	public function inCache($file) {
92
		return false;
93
	}
94
95
	public function remove($file) {
96
	}
97
98
	public function move($source, $target) {
99
	}
100
101
	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
102
	}
103
104
	public function clear() {
105
	}
106
107
	public function getStatus($file) {
108
		return ICache::NOT_FOUND;
109
	}
110
111
	public function search($pattern) {
112
		return [];
113
	}
114
115
	public function searchByMime($mimetype) {
116
		return [];
117
	}
118
119
	public function searchQuery(ISearchQuery $query) {
120
		return [];
121
	}
122
123
	public function getAll() {
124
		return [];
125
	}
126
127
	public function getIncomplete() {
128
		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...
129
	}
130
131
	public function getPathById($id) {
132
		return null;
133
	}
134
135
	public function normalize($path) {
136
		return $path;
137
	}
138
139
	public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {
140
		throw new \Exception("Invalid cache");
141
	}
142
}
143