Complex classes like SessionFunctions 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 SessionFunctions, and based on these observations, apply Extract Interface, too.
1 | <?php namespace Limoncello\Application\Session; |
||
31 | class SessionFunctions implements SessionFunctionsInterface |
||
32 | { |
||
33 | /** |
||
34 | * @var callable |
||
35 | */ |
||
36 | private $retrieveCallable; |
||
37 | |||
38 | /** |
||
39 | * @var callable |
||
40 | */ |
||
41 | private $putCallable; |
||
42 | |||
43 | /** |
||
44 | * @var callable |
||
45 | */ |
||
46 | private $hasCallable; |
||
47 | |||
48 | /** |
||
49 | * @var callable |
||
50 | */ |
||
51 | private $deleteCallable; |
||
52 | |||
53 | /** |
||
54 | * @var callable |
||
55 | */ |
||
56 | private $iteratorCallable; |
||
57 | |||
58 | /** |
||
59 | * @var callable |
||
60 | */ |
||
61 | private $abortCallable; |
||
62 | |||
63 | /** |
||
64 | * @var callable |
||
65 | */ |
||
66 | private $cacheLimiterCallable; |
||
67 | |||
68 | /** |
||
69 | * @var callable |
||
70 | */ |
||
71 | private $createIdCallable; |
||
72 | |||
73 | /** |
||
74 | * @var callable |
||
75 | */ |
||
76 | private $writeCloseCallable; |
||
77 | |||
78 | /** |
||
79 | * @var callable |
||
80 | */ |
||
81 | private $unsetCallable; |
||
82 | |||
83 | /** |
||
84 | * @var callable |
||
85 | */ |
||
86 | private $statusCallable; |
||
87 | |||
88 | /** |
||
89 | * @var callable |
||
90 | */ |
||
91 | private $startCallable; |
||
92 | |||
93 | /** |
||
94 | * @var callable |
||
95 | */ |
||
96 | private $setSaveHandlerCallable; |
||
97 | |||
98 | /** |
||
99 | * @var callable |
||
100 | */ |
||
101 | private $setCookieParamsCallable; |
||
102 | |||
103 | /** |
||
104 | * @var callable |
||
105 | */ |
||
106 | private $savePathCallable; |
||
107 | |||
108 | /** |
||
109 | * @var callable |
||
110 | */ |
||
111 | private $resetCallable; |
||
112 | |||
113 | /** |
||
114 | * @var callable |
||
115 | */ |
||
116 | private $registerShutdownCallable; |
||
117 | |||
118 | /** |
||
119 | * @var callable |
||
120 | */ |
||
121 | private $regenerateIdCallable; |
||
122 | |||
123 | /** |
||
124 | * @var callable |
||
125 | */ |
||
126 | private $nameCallable; |
||
127 | |||
128 | /** |
||
129 | * @var callable |
||
130 | */ |
||
131 | private $moduleNameCallable; |
||
132 | |||
133 | /** |
||
134 | * @var callable |
||
135 | */ |
||
136 | private $decodeCallable; |
||
137 | |||
138 | /** |
||
139 | * @var callable |
||
140 | */ |
||
141 | private $destroyCallable; |
||
142 | |||
143 | /** |
||
144 | * @var callable |
||
145 | */ |
||
146 | private $encodeCallable; |
||
147 | |||
148 | /** |
||
149 | * @var callable |
||
150 | */ |
||
151 | private $gcCallable; |
||
152 | |||
153 | /** |
||
154 | * @var callable |
||
155 | */ |
||
156 | private $getCookieParamsCallable; |
||
157 | |||
158 | /** |
||
159 | * @var callable |
||
160 | */ |
||
161 | private $idCallable; |
||
162 | |||
163 | /** |
||
164 | * @var callable |
||
165 | */ |
||
166 | private $cacheExpireCallable; |
||
167 | |||
168 | /** |
||
169 | * @var callable |
||
170 | */ |
||
171 | private $couldBeStartedCallable; |
||
172 | |||
173 | /** |
||
174 | * Constructor. |
||
175 | */ |
||
176 | 3 | public function __construct() |
|
220 | |||
221 | /** |
||
222 | * @inheritdoc |
||
223 | */ |
||
224 | 1 | public function getRetrieveCallable(): callable |
|
228 | |||
229 | /** |
||
230 | * @inheritdoc |
||
231 | */ |
||
232 | 3 | public function setRetrieveCallable(callable $callable): SessionFunctionsInterface |
|
238 | |||
239 | /** |
||
240 | * @inheritdoc |
||
241 | */ |
||
242 | 1 | public function getPutCallable(): callable |
|
246 | |||
247 | /** |
||
248 | * @inheritdoc |
||
249 | */ |
||
250 | 3 | public function setPutCallable(callable $callable): SessionFunctionsInterface |
|
256 | |||
257 | /** |
||
258 | * @inheritdoc |
||
259 | */ |
||
260 | 1 | public function getHasCallable(): callable |
|
264 | |||
265 | /** |
||
266 | * @inheritdoc |
||
267 | */ |
||
268 | 3 | public function setHasCallable(callable $callable): SessionFunctionsInterface |
|
274 | |||
275 | /** |
||
276 | * @inheritdoc |
||
277 | */ |
||
278 | 1 | public function getDeleteCallable(): callable |
|
282 | |||
283 | /** |
||
284 | * @inheritdoc |
||
285 | */ |
||
286 | 3 | public function setDeleteCallable(callable $callable): SessionFunctionsInterface |
|
292 | |||
293 | /** |
||
294 | * @inheritdoc |
||
295 | */ |
||
296 | 1 | public function getIteratorCallable(): callable |
|
300 | |||
301 | /** |
||
302 | * @inheritdoc |
||
303 | */ |
||
304 | 3 | public function setIteratorCallable(callable $callable): SessionFunctionsInterface |
|
310 | |||
311 | /** |
||
312 | * @inheritdoc |
||
313 | */ |
||
314 | 1 | public function getAbortCallable(): callable |
|
318 | |||
319 | /** |
||
320 | * @inheritdoc |
||
321 | */ |
||
322 | 3 | public function setAbortCallable(callable $callable): SessionFunctionsInterface |
|
328 | |||
329 | /** |
||
330 | * @inheritdoc |
||
331 | */ |
||
332 | 1 | public function getCacheExpireCallable(): callable |
|
336 | |||
337 | /** |
||
338 | * @inheritdoc |
||
339 | */ |
||
340 | 3 | public function setCacheExpireCallable(callable $callable): SessionFunctionsInterface |
|
346 | |||
347 | /** |
||
348 | * @inheritdoc |
||
349 | */ |
||
350 | 1 | public function getCacheLimiterCallable(): callable |
|
354 | |||
355 | /** |
||
356 | * @inheritdoc |
||
357 | */ |
||
358 | 3 | public function setCacheLimiterCallable(callable $callable): SessionFunctionsInterface |
|
364 | |||
365 | /** |
||
366 | * @inheritdoc |
||
367 | */ |
||
368 | 1 | public function getCreateIdCallable(): callable |
|
372 | |||
373 | /** |
||
374 | * @inheritdoc |
||
375 | */ |
||
376 | 3 | public function setCreateIdCallable(callable $callable): SessionFunctionsInterface |
|
382 | |||
383 | /** |
||
384 | * @inheritdoc |
||
385 | */ |
||
386 | 1 | public function getDecodeCallable(): callable |
|
390 | |||
391 | /** |
||
392 | * @inheritdoc |
||
393 | */ |
||
394 | 3 | public function setDecodeCallable(callable $callable): SessionFunctionsInterface |
|
400 | |||
401 | /** |
||
402 | * @inheritdoc |
||
403 | */ |
||
404 | 1 | public function getDestroyCallable(): callable |
|
408 | |||
409 | /** |
||
410 | * @inheritdoc |
||
411 | */ |
||
412 | 3 | public function setDestroyCallable(callable $callable): SessionFunctionsInterface |
|
418 | |||
419 | /** |
||
420 | * @inheritdoc |
||
421 | */ |
||
422 | 1 | public function getEncodeCallable(): callable |
|
426 | |||
427 | /** |
||
428 | * @inheritdoc |
||
429 | */ |
||
430 | 3 | public function setEncodeCallable(callable $callable): SessionFunctionsInterface |
|
436 | |||
437 | /** |
||
438 | * @inheritdoc |
||
439 | */ |
||
440 | 1 | public function getGcCallable(): callable |
|
444 | |||
445 | /** |
||
446 | * @inheritdoc |
||
447 | */ |
||
448 | 3 | public function setGcCallable(callable $callable): SessionFunctionsInterface |
|
454 | |||
455 | /** |
||
456 | * @inheritdoc |
||
457 | */ |
||
458 | 1 | public function getGetCookieParamsCallable(): callable |
|
462 | |||
463 | /** |
||
464 | * @inheritdoc |
||
465 | */ |
||
466 | 3 | public function setGetCookieParamsCallable(callable $callable): SessionFunctionsInterface |
|
472 | |||
473 | /** |
||
474 | * @inheritdoc |
||
475 | */ |
||
476 | 1 | public function getIdCallable(): callable |
|
480 | |||
481 | /** |
||
482 | * @inheritdoc |
||
483 | */ |
||
484 | 3 | public function setIdCallable(callable $callable): SessionFunctionsInterface |
|
490 | |||
491 | /** |
||
492 | * @inheritdoc |
||
493 | */ |
||
494 | 1 | public function getModuleNameCallable(): callable |
|
498 | |||
499 | /** |
||
500 | * @inheritdoc |
||
501 | */ |
||
502 | 3 | public function setModuleNameCallable(callable $callable): SessionFunctionsInterface |
|
508 | |||
509 | /** |
||
510 | * @inheritdoc |
||
511 | */ |
||
512 | 1 | public function getNameCallable(): callable |
|
516 | |||
517 | /** |
||
518 | * @inheritdoc |
||
519 | */ |
||
520 | 3 | public function setNameCallable(callable $callable): SessionFunctionsInterface |
|
526 | |||
527 | /** |
||
528 | * @inheritdoc |
||
529 | */ |
||
530 | 1 | public function getRegenerateIdCallable(): callable |
|
534 | |||
535 | /** |
||
536 | * @inheritdoc |
||
537 | */ |
||
538 | 3 | public function setRegenerateIdCallable(callable $callable): SessionFunctionsInterface |
|
544 | |||
545 | /** |
||
546 | * @inheritdoc |
||
547 | */ |
||
548 | 1 | public function getRegisterShutdownCallable(): callable |
|
552 | |||
553 | /** |
||
554 | * @inheritdoc |
||
555 | */ |
||
556 | 3 | public function setRegisterShutdownCallable(callable $callable): SessionFunctionsInterface |
|
562 | |||
563 | /** |
||
564 | * @inheritdoc |
||
565 | */ |
||
566 | 1 | public function getResetCallable(): callable |
|
570 | |||
571 | /** |
||
572 | * @inheritdoc |
||
573 | */ |
||
574 | 3 | public function setResetCallable(callable $callable): SessionFunctionsInterface |
|
580 | |||
581 | /** |
||
582 | * @inheritdoc |
||
583 | */ |
||
584 | 1 | public function getSavePathCallable(): callable |
|
588 | |||
589 | /** |
||
590 | * @inheritdoc |
||
591 | */ |
||
592 | 3 | public function setSavePathCallable(callable $callable): SessionFunctionsInterface |
|
598 | |||
599 | /** |
||
600 | * @inheritdoc |
||
601 | */ |
||
602 | 1 | public function getSetCookieParamsCallable(): callable |
|
606 | |||
607 | /** |
||
608 | * @inheritdoc |
||
609 | */ |
||
610 | 3 | public function setSetCookieParamsCallable(callable $callable): SessionFunctionsInterface |
|
616 | |||
617 | /** |
||
618 | * @inheritdoc |
||
619 | */ |
||
620 | 1 | public function getSetSaveHandlerCallable(): callable |
|
624 | |||
625 | /** |
||
626 | * @inheritdoc |
||
627 | */ |
||
628 | 3 | public function setSetSaveHandlerCallable(callable $callable): SessionFunctionsInterface |
|
634 | |||
635 | /** |
||
636 | * @inheritdoc |
||
637 | */ |
||
638 | 2 | public function getStartCallable(): callable |
|
642 | |||
643 | /** |
||
644 | * @inheritdoc |
||
645 | */ |
||
646 | 3 | public function setStartCallable(callable $callable): SessionFunctionsInterface |
|
652 | |||
653 | /** |
||
654 | * @inheritdoc |
||
655 | */ |
||
656 | 1 | public function getStatusCallable(): callable |
|
660 | |||
661 | /** |
||
662 | * @inheritdoc |
||
663 | */ |
||
664 | 3 | public function setStatusCallable(callable $callable): SessionFunctionsInterface |
|
670 | |||
671 | /** |
||
672 | * @inheritdoc |
||
673 | */ |
||
674 | 1 | public function getUnsetCallable(): callable |
|
678 | |||
679 | /** |
||
680 | * @inheritdoc |
||
681 | */ |
||
682 | 3 | public function setUnsetCallable(callable $callable): SessionFunctionsInterface |
|
688 | |||
689 | /** |
||
690 | * @inheritdoc |
||
691 | */ |
||
692 | 2 | public function getWriteCloseCallable(): callable |
|
696 | |||
697 | /** |
||
698 | * @inheritdoc |
||
699 | */ |
||
700 | 3 | public function setWriteCloseCallable(callable $callable): SessionFunctionsInterface |
|
706 | |||
707 | /** |
||
708 | * @inheritdoc |
||
709 | */ |
||
710 | 1 | public function getCouldBeStartedCallable(): callable |
|
714 | |||
715 | /** |
||
716 | * @inheritdoc |
||
717 | */ |
||
718 | 3 | public function setCouldBeStartedCallable(callable $callable): SessionFunctionsInterface |
|
724 | } |
||
725 |