Completed
Push — master ( 8f38ad...4035d6 )
by Joas
13:12 queued 06:02
created

NullCache::search()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (c) 2016, Robin Appelman <[email protected]>
5
 *
6
 * This code is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License, version 3,
8
 * as published by the Free Software Foundation.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License, version 3,
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
17
 *
18
 */
19
20
namespace OC\Lockdown\Filesystem;
21
22
use OC\Files\Cache\CacheEntry;
23
use OCP\Constants;
24
use OCP\Files\Cache\ICache;
25
use OCP\Files\Cache\ICacheEntry;
26
use OCP\Files\FileInfo;
27
28
class NullCache implements ICache {
29
	public function getNumericStorageId() {
30
		return -1;
31
	}
32
33
	public function get($file) {
34
		return $file !== '' ? null :
35
			new CacheEntry([
36
				'fileid' => -1,
37
				'parent' => -1,
38
				'name' => '',
39
				'path' => '',
40
				'size' => '0',
41
				'mtime' => time(),
42
				'storage_mtime' => time(),
43
				'etag' => '',
44
				'mimetype' => FileInfo::MIMETYPE_FOLDER,
45
				'mimepart' => 'httpd',
46
				'permissions' => Constants::PERMISSION_READ
47
			]);
48
	}
49
50
	public function getFolderContents($folder) {
51
		return [];
52
	}
53
54
	public function getFolderContentsById($fileId) {
55
		return [];
56
	}
57
58
	public function put($file, array $data) {
59
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
60
	}
61
62
	public function insert($file, array $data) {
63
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
64
	}
65
66
	public function update($id, array $data) {
67
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
68
	}
69
70
	public function getId($file) {
71
		return -1;
72
	}
73
74
	public function getParentId($file) {
75
		return -1;
76
	}
77
78
	public function inCache($file) {
79
		return $file === '';
80
	}
81
82
	public function remove($file) {
83
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
84
	}
85
86
	public function move($source, $target) {
87
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
88
	}
89
90
	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
91
		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
92
	}
93
94
	public function getStatus($file) {
95
		return ICache::COMPLETE;
96
	}
97
98
	public function search($pattern) {
99
		return [];
100
	}
101
102
	public function searchByMime($mimetype) {
103
		return [];
104
	}
105
106
	public function searchByTag($tag, $userId) {
107
		return [];
108
	}
109
110
	public function getIncomplete() {
111
		return [];
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array(); (array) is incompatible with the return type declared by the interface OCP\Files\Cache\ICache::getIncomplete of type string|boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
112
	}
113
114
	public function getPathById($id) {
115
		return '';
116
	}
117
118
	public function normalize($path) {
119
		return $path;
120
	}
121
122
}
123