Completed
Push — master ( 96ed5e...b2d2f0 )
by Simon
01:52
created

CommunityUser::isNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * User data object
5
 */
6
class CommunityUser extends User
7
{
8
	public function getId()
9
	{
10
		return -1;
11
	}
12
    
13
	public function save()
14
	{
15
		// Do nothing
16
	}
17
18
	public function authenticate($password)
19
	{
20
		// Impossible to log in as this user
21
		return false;
22
	}
23
    
24
	public function touchLastLogin()
25
	{
26
	}
27
    
28
	#region properties
29
    
30
	public function getUsername()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
31
	{
32
		global $communityUsername;
33
		return $communityUsername;
34
	}
35
36
	public function setUsername($username)
37
	{
38
	}
39
40
	public function getEmail()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
41
	{
42
		global $cDataClearEmail;
43
		return $cDataClearEmail;
44
	}
45
46
	public function setEmail($email)
47
	{
48
	}
49
50
	public function setPassword($password)
51
	{
52
	}
53
54
	public function getStatus()
55
	{
56
		return "Community";
57
	}
58
59
	public function getOnWikiName()
60
	{
61
		return "127.0.0.1";
62
	}
63
    
64
	public function getStoredOnWikiName()
65
	{
66
		return $this->getOnWikiName();
67
	}
68
69
	public function setOnWikiName($onWikiName)
70
	{
71
	}
72
73
	public function getWelcomeSig()
74
	{
75
		return null;
76
	}
77
78
	public function setWelcomeSig($welcomeSig)
79
	{
80
	}
81
82
	public function getLastActive()
83
	{
84
		$now = new DateTime();
85
		return $now->format("Y-m-d H:i:s");
86
	}
87
88
	public function setLastActive($lastActive)
89
	{
90
	}
91
92
	public function getForcelogout()
93
	{
94
		return 1;
95
	}
96
97
	public function setForcelogout($forceLogout)
98
	{
99
	}
100
    
101
	public function getSecure()
102
	{
103
		return true;
104
	}
105
106
	/**
107
	 * @return int
108
	 */
109
	public function getCheckuser()
110
	{
111
		return 0;
112
	}
113
114
	public function setCheckuser($checkuser)
115
	{
116
	}
117
118
	public function getIdentified()
119
	{
120
		return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type of the parent method User::getIdentified of type integer.

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...
121
	}
122
123
	public function setIdentified($identified)
124
	{
125
	}
126
127
	public function getWelcomeTemplate()
128
	{
129
		return 0;
130
	}
131
132
	public function setWelcomeTemplate($welcomeTemplate)
133
	{
134
	}
135
136
	public function getAbortPref()
137
	{
138
		return 0;
139
	}
140
141
	public function setAbortPref($abortPreference)
142
	{
143
	}
144
145
	public function getConfirmationDiff()
146
	{
147
		return null;
148
	}
149
150
	public function setConfirmationDiff($confirmationDiff)
151
	{
152
	}
153
154
	public function getEmailSig()
155
	{
156
		return null;
157
	}
158
159
	public function setEmailSig($emailSignature)
160
	{
161
	}
162
    
163
	#endregion
164
    
165
	#region changing access level
166
	public function approve()
167
	{
168
	}
169
    
170
	public function suspend($comment)
171
	{
172
	}
173
    
174
	public function decline($comment)
175
	{
176
	}
177
    
178
	public function promote()
179
	{
180
	}
181
    
182
	public function demote($comment)
183
	{
184
	}
185
186
	#endregion
187
    
188
	#region user access checks
189
    
190
	public function isAdmin()
191
	{
192
		return false;
193
	}
194
    
195
	public function isCheckuser()
196
	{
197
		return false;
198
	}
199
    
200
	public function isSuspended()
201
	{
202
		return false;
203
	}
204
    
205
	public function isNew()
206
	{
207
		return false;
208
	}
209
    
210
	public function isUser()
211
	{
212
		return false;
213
	}
214
    
215
	public function isDeclined()
216
	{
217
		return false;
218
	}
219
    
220
	public function isCommunityUser()
221
	{
222
		return true;
223
	}
224
    
225
	#endregion 
226
227
	#region OAuth
228
    
229
	public function getOAuthIdentity($useCached = false)
230
	{
231
		return null;
232
	}
233
    
234
	public function isOAuthLinked()
235
	{
236
		return false;
237
	}
238
    
239
	public function detachAccount()
240
	{
241
	}
242
    
243
	public function oauthCanUse()
244
	{
245
		return false;
246
	}
247
    
248
	public function oauthCanEdit()
249
	{
250
		return false;
251
	}
252
    
253
	public function oauthCanCreateAccount()
254
	{
255
		return false;
256
	}
257
258
	protected function oauthCanCheckUser()
259
	{
260
		return false;
261
	}
262
    
263
	#endregion
264
265
	public function getApprovalDate()
266
	{
267
		$data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00");
268
		return $data;
269
	}
270
}
271