Failed Conditions
Branch newinternal (bd75e4)
by Simon
03:48
created

CommunityUser   B

Complexity

Total Complexity 41

Size/Duplication

Total Lines 226
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 41
c 5
b 0
f 0
lcom 0
cbo 1
dl 0
loc 226
ccs 0
cts 156
cp 0
rs 8.2769

41 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A save() 0 4 1
A authenticate() 0 5 1
A getUsername() 0 6 1
A setUsername() 0 3 1
A getEmail() 0 6 1
A setEmail() 0 3 1
A setPassword() 0 3 1
A getStatus() 0 4 1
A getOnWikiName() 0 4 1
A getStoredOnWikiName() 0 4 1
A setOnWikiName() 0 3 1
A getWelcomeSig() 0 4 1
A setWelcomeSig() 0 3 1
A getLastActive() 0 6 1
A getForceLogout() 0 4 1
A setForceLogout() 0 3 1
A setStatus() 0 3 1
A getWelcomeTemplate() 0 4 1
A setWelcomeTemplate() 0 3 1
A getAbortPref() 0 4 1
A setAbortPref() 0 3 1
A getConfirmationDiff() 0 4 1
A setConfirmationDiff() 0 3 1
A getEmailSig() 0 4 1
A setEmailSig() 0 3 1
A isAdmin() 0 4 1
A isCheckuser() 0 4 1
A isIdentified() 0 4 1
A isSuspended() 0 4 1
A isNewUser() 0 4 1
A isUser() 0 4 1
A isDeclined() 0 4 1
A isCommunityUser() 0 4 1
A getOAuthIdentity() 0 4 1
A isOAuthLinked() 0 4 1
A oauthCanUse() 0 4 1
A oauthCanEdit() 0 4 1
A oauthCanCreateAccount() 0 4 1
A oauthCanCheckUser() 0 4 1
A getApprovalDate() 0 6 1

How to fix   Complexity   

Complex Class

Complex classes like CommunityUser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use CommunityUser, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Waca\DataObjects;
4
5
use DateTime;
6
use Waca\IdentificationVerifier;
7
8
/**
9
 * User data object
10
 */
11
class CommunityUser extends User
12
{
13
	public function getId()
14
	{
15
		return -1;
16
	}
17
18
	public function save()
19
	{
20
		// Do nothing
21
	}
22
23
	public function authenticate($password)
24
	{
25
		// Impossible to log in as this user
26
		return false;
27
	}
28
29
	#region properties
30
31
	/**
32
	 * @return string
33
	 */
34
	public function getUsername()
35
	{
36
		global $communityUsername;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
37
38
		return $communityUsername;
39
	}
40
41
	public function setUsername($username)
42
	{
43
	}
44
45
	/**
46
	 * @return string
47
	 */
48
	public function getEmail()
49
	{
50
		global $cDataClearEmail;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
51
52
		return $cDataClearEmail;
53
	}
54
55
	public function setEmail($email)
56
	{
57
	}
58
59
	public function setPassword($password)
60
	{
61
	}
62
63
	public function getStatus()
64
	{
65
		return "Community";
66
	}
67
68
	public function getOnWikiName()
69
	{
70
		return "127.0.0.1";
71
	}
72
73
	public function getStoredOnWikiName()
74
	{
75
		return $this->getOnWikiName();
76
	}
77
78
	public function setOnWikiName($onWikiName)
79
	{
80
	}
81
82
	public function getWelcomeSig()
83
	{
84
		return null;
85
	}
86
87
	public function setWelcomeSig($welcomeSig)
88
	{
89
	}
90
91
	public function getLastActive()
92
	{
93
		$now = new DateTime();
94
95
		return $now->format("Y-m-d H:i:s");
96
	}
97
98
	public function getForceLogout()
99
	{
100
		return true;
101
	}
102
103
	public function setForceLogout($forceLogout)
104
	{
105
	}
106
107
	/**
108
	 * @param string $status
109
	 */
110
	public function setStatus($status)
111
	{
112
	}
113
114
	public function getWelcomeTemplate()
115
	{
116
		return 0;
117
	}
118
119
	public function setWelcomeTemplate($welcomeTemplate)
120
	{
121
	}
122
123
	public function getAbortPref()
124
	{
125
		return 0;
126
	}
127
128
	public function setAbortPref($abortPreference)
129
	{
130
	}
131
132
	public function getConfirmationDiff()
133
	{
134
		return null;
135
	}
136
137
	public function setConfirmationDiff($confirmationDiff)
138
	{
139
	}
140
141
	public function getEmailSig()
142
	{
143
		return null;
144
	}
145
146
	public function setEmailSig($emailSignature)
147
	{
148
	}
149
150
	#endregion
151
152
	#region user access checks
153
154
	public function isAdmin()
155
	{
156
		return false;
157
	}
158
159
	public function isCheckuser()
160
	{
161
		return false;
162
	}
163
164
	public function isIdentified(IdentificationVerifier $iv)
165
	{
166
		return false;
167
	}
168
169
	public function isSuspended()
170
	{
171
		return false;
172
	}
173
174
	public function isNewUser()
175
	{
176
		return false;
177
	}
178
179
	public function isUser()
180
	{
181
		return false;
182
	}
183
184
	public function isDeclined()
185
	{
186
		return false;
187
	}
188
189
	public function isCommunityUser()
190
	{
191
		return true;
192
	}
193
194
	#endregion 
195
196
	#region OAuth
197
198
	public function getOAuthIdentity($useCached = false)
199
	{
200
		return null;
201
	}
202
203
	public function isOAuthLinked()
204
	{
205
		return false;
206
	}
207
208
	public function oauthCanUse()
209
	{
210
		return false;
211
	}
212
213
	public function oauthCanEdit()
214
	{
215
		return false;
216
	}
217
218
	public function oauthCanCreateAccount()
219
	{
220
		return false;
221
	}
222
223
	protected function oauthCanCheckUser()
224
	{
225
		return false;
226
	}
227
228
	#endregion
229
230
	public function getApprovalDate()
231
	{
232
		$data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00");
233
234
		return $data;
235
	}
236
}
237