Completed
Pull Request — master (#31951)
by Jörn Friedrich
10:58
created

RemoteUser::getQuota()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Thomas Müller <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OC\User;
23
24
use OCP\IUser;
25
26
/**
27
 * Class RemoteUser - an implementation of IUser for user on a remote/federated server
28
 *
29
 * @package OC\User
30
 */
31
class RemoteUser implements IUser {
32
33
	/** @var string */
34
	private $userId;
35
36
	/**
37
	 * RemoteUser constructor.
38
	 *
39
	 * @param string $userId
40
	 */
41
	public function __construct($userId) {
42
		$this->userId = $userId;
43
	}
44
45
	/**
46
	 * @inheritdoc
47
	 */
48
	public function getUID() {
49
		return $this->userId;
50
	}
51
52
	/**
53
	 * @inheritdoc
54
	 */
55
	public function getUserName() {
56
		return $this->getUID();
57
	}
58
59
	/**
60
	 * @inheritdoc
61
	 */
62
	public function setUserName($userName) {
63
	}
64
65
	/**
66
	 * @inheritdoc
67
	 */
68
	public function getDisplayName() {
69
		return $this->userId;
70
	}
71
72
	/**
73
	 * @inheritdoc
74
	 */
75
	public function setDisplayName($displayName) {
76
		return false;
77
	}
78
79
	/**
80
	 * @inheritdoc
81
	 */
82
	public function getLastLogin() {
83
		return 0;
84
	}
85
86
	/**
87
	 * @inheritdoc
88
	 */
89
	public function updateLastLoginTimestamp() {
90
	}
91
92
	/**
93
	 * @inheritdoc
94
	 */
95
	public function delete() {
96
		return false;
97
	}
98
99
	/**
100
	 * @inheritdoc
101
	 */
102
	public function setPassword($password, $recoveryPassword = null) {
103
		return false;
104
	}
105
106
	/**
107
	 * @inheritdoc
108
	 */
109
	public function getHome() {
110
	}
111
112
	/**
113
	 * @inheritdoc
114
	 */
115
	public function getBackendClassName() {
116
		return 'Remote';
117
	}
118
119
	/**
120
	 * @inheritdoc
121
	 */
122
	public function canChangeAvatar() {
123
		return false;
124
	}
125
126
	/**
127
	 * @inheritdoc
128
	 */
129
	public function canChangePassword() {
130
		return false;
131
	}
132
133
	/**
134
	 * @inheritdoc
135
	 */
136
	public function canChangeDisplayName() {
137
		return false;
138
	}
139
140
	/**
141
	 * @inheritdoc
142
	 */
143
	public function isEnabled() {
144
		return true;
145
	}
146
147
	/**
148
	 * @inheritdoc
149
	 */
150
	public function setEnabled($enabled) {
151
		return false;
152
	}
153
154
	/**
155
	 * @inheritdoc
156
	 */
157
	public function getEMailAddress() {
158
		return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type declared by the interface OCP\IUser::getEMailAddress of type string|null.

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...
159
	}
160
161
	/**
162
	 * @inheritdoc
163
	 */
164
	public function getAvatarImage($size) {
165
		return null;
166
	}
167
168
	/**
169
	 * @inheritdoc
170
	 */
171
	public function getCloudId() {
172
		$uid = $this->getUID();
173
		$server = \OC::$server->getURLGenerator()->getAbsoluteURL('/');
174
		return $uid . '@' . \rtrim($this->removeProtocolFromUrl($server), '/');
175
	}
176
177
	/**
178
	 * @param string $url
179
	 * @return string
180
	 */
181 View Code Duplication
	private function removeProtocolFromUrl($url) {
182
		if (\strpos($url, 'https://') === 0) {
183
			return \substr($url, \strlen('https://'));
184
		} elseif (\strpos($url, 'http://') === 0) {
185
			return \substr($url, \strlen('http://'));
186
		}
187
188
		return $url;
189
	}
190
191
	/**
192
	 * @inheritdoc
193
	 */
194
	public function setEMailAddress($mailAddress) {
195
	}
196
197
	/**
198
	 * @inheritdoc
199
	 */
200
	public function getQuota() {
201
		return 'none';
202
	}
203
204
	/**
205
	 * @inheritdoc
206
	 */
207
	public function setQuota($quota) {
208
	}
209
210
	/**
211
	 * @inheritdoc
212
	 */
213
	public function getSearchTerms() {
214
		return [];
215
	}
216
217
	/**
218
	 * @inheritdoc
219
	 */
220
	public function setSearchTerms(array $terms) {
221
	}
222
223
	/**
224
	 * @return integer
225
	 * @since 11.0.0
226
	 */
227
	public function getAccountId() {
228
		return null;
229
	}
230
}
231