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 |
||
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() |
||
31 | { |
||
32 | global $communityUsername; |
||
33 | return $communityUsername; |
||
34 | } |
||
35 | |||
36 | public function setUsername($username) |
||
37 | { |
||
38 | } |
||
39 | |||
40 | public function getEmail() |
||
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; |
||
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() |
||
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 |