Complex classes like ModuleOptions 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 ModuleOptions, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class ModuleOptions extends AbstractOptions implements |
||
8 | UserControllerOptionsInterface, |
||
9 | UserServiceOptionsInterface |
||
10 | { |
||
11 | /** |
||
12 | * Turn off strict options mode |
||
13 | */ |
||
14 | protected $__strictMode__ = false; |
||
15 | |||
16 | /** |
||
17 | * @var bool |
||
18 | */ |
||
19 | protected $useRedirectParameterIfPresent = true; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $loginRedirectRoute = 'zfcuser'; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $logoutRedirectRoute = 'zfcuser/login'; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $loginFormTimeout = 300; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | protected $userFormTimeout = 300; |
||
40 | |||
41 | /** |
||
42 | * @var bool |
||
43 | */ |
||
44 | protected $loginAfterRegistration = true; |
||
45 | |||
46 | /** |
||
47 | * @var int |
||
48 | */ |
||
49 | protected $enableUserState = false; |
||
50 | |||
51 | /** |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $defaultUserState = 1; |
||
55 | |||
56 | /** |
||
57 | * @var Array |
||
58 | */ |
||
59 | protected $allowedLoginStates = array( null, 1 ); |
||
60 | |||
61 | /** |
||
62 | * @var array |
||
63 | */ |
||
64 | protected $authAdapters = array( 100 => 'ZfcUser\Authentication\Adapter\Db' ); |
||
65 | |||
66 | /** |
||
67 | * @var array |
||
68 | */ |
||
69 | protected $authIdentityFields = array( 'email' ); |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $userEntityClass = 'ZfcUser\Entity\User'; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $userLoginWidgetViewTemplate = 'zfc-user/user/login.phtml'; |
||
80 | |||
81 | /** |
||
82 | * @var bool |
||
83 | */ |
||
84 | protected $enableRegistration = true; |
||
85 | |||
86 | /** |
||
87 | * @var bool |
||
88 | */ |
||
89 | protected $enableUsername = false; |
||
90 | |||
91 | /** |
||
92 | * @var bool |
||
93 | */ |
||
94 | protected $enableDisplayName = false; |
||
95 | |||
96 | /** |
||
97 | * @var bool |
||
98 | */ |
||
99 | protected $useRegistrationFormCaptcha = false; |
||
100 | |||
101 | /** |
||
102 | * @var int |
||
103 | */ |
||
104 | protected $passwordCost = 14; |
||
105 | |||
106 | /** |
||
107 | * @var string |
||
108 | */ |
||
109 | |||
110 | protected $tableName = 'user'; |
||
111 | |||
112 | /** |
||
113 | * @var array |
||
114 | */ |
||
115 | protected $formCaptchaOptions = array( |
||
116 | 'class' => 'figlet', |
||
117 | 'options' => array( |
||
118 | 'wordLen' => 5, |
||
119 | 'expiration' => 300, |
||
120 | 'timeout' => 300, |
||
121 | ), |
||
122 | ); |
||
123 | |||
124 | /** |
||
125 | * set login redirect route |
||
126 | * |
||
127 | * @param string $loginRedirectRoute |
||
128 | * @return ModuleOptions |
||
129 | */ |
||
130 | public function setLoginRedirectRoute($loginRedirectRoute) |
||
131 | { |
||
132 | $this->loginRedirectRoute = $loginRedirectRoute; |
||
133 | return $this; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * get login redirect route |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getLoginRedirectRoute() |
||
145 | |||
146 | /** |
||
147 | * set logout redirect route |
||
148 | * |
||
149 | * @param string $logoutRedirectRoute |
||
150 | * @return ModuleOptions |
||
151 | */ |
||
152 | public function setLogoutRedirectRoute($logoutRedirectRoute) |
||
153 | { |
||
154 | $this->logoutRedirectRoute = $logoutRedirectRoute; |
||
155 | return $this; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * get logout redirect route |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getLogoutRedirectRoute() |
||
167 | |||
168 | /** |
||
169 | * set use redirect param if present |
||
170 | * |
||
171 | * @param bool $useRedirectParameterIfPresent |
||
172 | * @return ModuleOptions |
||
173 | */ |
||
174 | public function setUseRedirectParameterIfPresent($useRedirectParameterIfPresent) |
||
175 | { |
||
176 | $this->useRedirectParameterIfPresent = $useRedirectParameterIfPresent; |
||
177 | return $this; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * get use redirect param if present |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | public function getUseRedirectParameterIfPresent() |
||
189 | |||
190 | /** |
||
191 | * set the view template for the user login widget |
||
192 | * |
||
193 | * @param string $userLoginWidgetViewTemplate |
||
194 | * @return ModuleOptions |
||
195 | */ |
||
196 | public function setUserLoginWidgetViewTemplate($userLoginWidgetViewTemplate) |
||
197 | { |
||
198 | $this->userLoginWidgetViewTemplate = $userLoginWidgetViewTemplate; |
||
199 | return $this; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * get the view template for the user login widget |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | public function getUserLoginWidgetViewTemplate() |
||
211 | |||
212 | /** |
||
213 | * set enable user registration |
||
214 | * |
||
215 | * @param bool $enableRegistration |
||
216 | * @return ModuleOptions |
||
217 | */ |
||
218 | public function setEnableRegistration($enableRegistration) |
||
219 | { |
||
220 | $this->enableRegistration = $enableRegistration; |
||
221 | return $this; |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * get enable user registration |
||
226 | * |
||
227 | * @return bool |
||
228 | */ |
||
229 | public function getEnableRegistration() |
||
233 | |||
234 | /** |
||
235 | * set login form timeout |
||
236 | * |
||
237 | * @param int $loginFormTimeout |
||
238 | * @return ModuleOptions |
||
239 | */ |
||
240 | public function setLoginFormTimeout($loginFormTimeout) |
||
241 | { |
||
242 | $this->loginFormTimeout = $loginFormTimeout; |
||
243 | return $this; |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * get login form timeout in seconds |
||
248 | * |
||
249 | * @return int |
||
250 | */ |
||
251 | public function getLoginFormTimeout() |
||
255 | |||
256 | /** |
||
257 | * set user form timeout in seconds |
||
258 | * |
||
259 | * @param int $userFormTimeout |
||
260 | * @return ModuleOptions |
||
261 | */ |
||
262 | public function setUserFormTimeout($userFormTimeout) |
||
263 | { |
||
264 | $this->userFormTimeout = $userFormTimeout; |
||
265 | return $this; |
||
266 | } |
||
267 | |||
268 | /** |
||
269 | * get user form timeout in seconds |
||
270 | * |
||
271 | * @return int |
||
272 | */ |
||
273 | public function getUserFormTimeout() |
||
277 | |||
278 | /** |
||
279 | * set login after registration |
||
280 | * |
||
281 | * @param bool $loginAfterRegistration |
||
282 | * @return ModuleOptions |
||
283 | */ |
||
284 | public function setLoginAfterRegistration($loginAfterRegistration) |
||
285 | { |
||
286 | $this->loginAfterRegistration = $loginAfterRegistration; |
||
287 | return $this; |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * get login after registration |
||
292 | * |
||
293 | * @return bool |
||
294 | */ |
||
295 | public function getLoginAfterRegistration() |
||
299 | |||
300 | /** |
||
301 | * get user state usage for registration/login process |
||
302 | * |
||
303 | * @return int |
||
304 | */ |
||
305 | public function getEnableUserState() |
||
309 | |||
310 | /** |
||
311 | * set user state usage for registration/login process |
||
312 | * |
||
313 | * @param boolean $flag |
||
314 | * @return ModuleOptions |
||
315 | */ |
||
316 | public function setEnableUserState($flag) |
||
317 | { |
||
318 | $this->enableUserState = $flag; |
||
319 | return $this; |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * get default user state on registration |
||
324 | * |
||
325 | * @return int |
||
326 | */ |
||
327 | public function getDefaultUserState() |
||
331 | |||
332 | /** |
||
333 | * set default user state on registration |
||
334 | * |
||
335 | * @param int $state |
||
336 | * @return ModuleOptions |
||
337 | */ |
||
338 | public function setDefaultUserState($state) |
||
339 | { |
||
340 | $this->defaultUserState = $state; |
||
341 | return $this; |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * get list of states to allow user login |
||
346 | * |
||
347 | * @return array |
||
348 | */ |
||
349 | public function getAllowedLoginStates() |
||
353 | |||
354 | /** |
||
355 | * set list of states to allow user login |
||
356 | * |
||
357 | * @param Array $states |
||
358 | * @return ModuleOptions |
||
359 | */ |
||
360 | public function setAllowedLoginStates(Array $states) |
||
361 | { |
||
362 | $this->allowedLoginStates = $states; |
||
363 | return $this; |
||
364 | } |
||
365 | |||
366 | /** |
||
367 | * set auth adapters |
||
368 | * |
||
369 | * @param array $authAdapterss |
||
370 | * @return ModuleOptions |
||
371 | */ |
||
372 | public function setAuthAdapters($authAdapters) |
||
373 | { |
||
374 | $this->authAdapters = $authAdapters; |
||
375 | return $this; |
||
376 | } |
||
377 | |||
378 | /** |
||
379 | * get auth adapters |
||
380 | * |
||
381 | * @return array |
||
382 | */ |
||
383 | public function getAuthAdapters() |
||
387 | |||
388 | /** |
||
389 | * set auth identity fields |
||
390 | * |
||
391 | * @param array $authIdentityFields |
||
392 | * @return ModuleOptions |
||
393 | */ |
||
394 | public function setAuthIdentityFields($authIdentityFields) |
||
395 | { |
||
396 | $this->authIdentityFields = $authIdentityFields; |
||
397 | return $this; |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * get auth identity fields |
||
402 | * |
||
403 | * @return array |
||
404 | */ |
||
405 | public function getAuthIdentityFields() |
||
409 | |||
410 | /** |
||
411 | * set enable username |
||
412 | * |
||
413 | * @param bool $flag |
||
414 | * @return ModuleOptions |
||
415 | */ |
||
416 | public function setEnableUsername($flag) |
||
417 | { |
||
418 | $this->enableUsername = (bool) $flag; |
||
419 | return $this; |
||
420 | } |
||
421 | |||
422 | /** |
||
423 | * get enable username |
||
424 | * |
||
425 | * @return bool |
||
426 | */ |
||
427 | public function getEnableUsername() |
||
431 | |||
432 | /** |
||
433 | * set enable display name |
||
434 | * |
||
435 | * @param bool $flag |
||
436 | * @return ModuleOptions |
||
437 | */ |
||
438 | public function setEnableDisplayName($flag) |
||
439 | { |
||
440 | $this->enableDisplayName = (bool) $flag; |
||
441 | return $this; |
||
442 | } |
||
443 | |||
444 | /** |
||
445 | * get enable display name |
||
446 | * |
||
447 | * @return bool |
||
448 | */ |
||
449 | public function getEnableDisplayName() |
||
453 | |||
454 | /** |
||
455 | * set use a captcha in registration form |
||
456 | * |
||
457 | * @param bool $useRegistrationFormCaptcha |
||
458 | * @return ModuleOptions |
||
459 | */ |
||
460 | public function setUseRegistrationFormCaptcha($useRegistrationFormCaptcha) |
||
461 | { |
||
462 | $this->useRegistrationFormCaptcha = $useRegistrationFormCaptcha; |
||
463 | return $this; |
||
464 | } |
||
465 | |||
466 | /** |
||
467 | * get use a captcha in registration form |
||
468 | * |
||
469 | * @return bool |
||
470 | */ |
||
471 | public function getUseRegistrationFormCaptcha() |
||
475 | |||
476 | /** |
||
477 | * set user entity class name |
||
478 | * |
||
479 | * @param string $userEntityClass |
||
480 | * @return ModuleOptions |
||
481 | */ |
||
482 | public function setUserEntityClass($userEntityClass) |
||
483 | { |
||
484 | $this->userEntityClass = $userEntityClass; |
||
485 | return $this; |
||
486 | } |
||
487 | |||
488 | /** |
||
489 | * get user entity class name |
||
490 | * |
||
491 | * @return string |
||
492 | */ |
||
493 | public function getUserEntityClass() |
||
497 | |||
498 | /** |
||
499 | * set password cost |
||
500 | * |
||
501 | * @param int $passwordCost |
||
502 | * @return ModuleOptions |
||
503 | */ |
||
504 | public function setPasswordCost($passwordCost) |
||
505 | { |
||
506 | $this->passwordCost = $passwordCost; |
||
507 | return $this; |
||
508 | } |
||
509 | |||
510 | /** |
||
511 | * get password cost |
||
512 | * |
||
513 | * @return int |
||
514 | */ |
||
515 | public function getPasswordCost() |
||
519 | |||
520 | /** |
||
521 | * set user table name |
||
522 | * |
||
523 | * @param string $tableName |
||
524 | */ |
||
525 | public function setTableName($tableName) |
||
529 | |||
530 | /** |
||
531 | * get user table name |
||
532 | * |
||
533 | * @return string |
||
534 | */ |
||
535 | public function getTableName() |
||
539 | |||
540 | /** |
||
541 | * set form CAPTCHA options |
||
542 | * |
||
543 | * @param array $formCaptchaOptions |
||
544 | * @return ModuleOptions |
||
545 | */ |
||
546 | public function setFormCaptchaOptions($formCaptchaOptions) |
||
547 | { |
||
548 | $this->formCaptchaOptions = $formCaptchaOptions; |
||
549 | return $this; |
||
550 | } |
||
551 | |||
552 | /** |
||
553 | * get form CAPTCHA options |
||
554 | * |
||
555 | * @return array |
||
556 | */ |
||
557 | public function getFormCaptchaOptions() |
||
561 | } |
||
562 |