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 | * @var callable |
||
164 | */ |
||
165 | private $cacheExpireCallable; |
||
166 | |||
167 | /** |
||
168 | * Constructor. |
||
169 | */ |
||
170 | public function __construct() |
||
211 | |||
212 | /** |
||
213 | * @inheritdoc |
||
214 | */ |
||
215 | 1 | public function getRetrieveCallable(): callable |
|
219 | |||
220 | /** |
||
221 | * @inheritdoc |
||
222 | */ |
||
223 | 3 | public function setRetrieveCallable(callable $callable): SessionFunctionsInterface |
|
229 | |||
230 | /** |
||
231 | * @inheritdoc |
||
232 | */ |
||
233 | 1 | public function getPutCallable(): callable |
|
237 | |||
238 | /** |
||
239 | * @inheritdoc |
||
240 | */ |
||
241 | 3 | public function setPutCallable(callable $callable): SessionFunctionsInterface |
|
247 | |||
248 | /** |
||
249 | * @inheritdoc |
||
250 | */ |
||
251 | 1 | public function getHasCallable(): callable |
|
255 | |||
256 | /** |
||
257 | * @inheritdoc |
||
258 | */ |
||
259 | 3 | public function setHasCallable(callable $callable): SessionFunctionsInterface |
|
265 | |||
266 | /** |
||
267 | * @inheritdoc |
||
268 | */ |
||
269 | 1 | public function getDeleteCallable(): callable |
|
273 | |||
274 | /** |
||
275 | * @inheritdoc |
||
276 | */ |
||
277 | 3 | public function setDeleteCallable(callable $callable): SessionFunctionsInterface |
|
283 | |||
284 | /** |
||
285 | * @inheritdoc |
||
286 | */ |
||
287 | 1 | public function getIteratorCallable(): callable |
|
291 | |||
292 | /** |
||
293 | * @inheritdoc |
||
294 | */ |
||
295 | 3 | public function setIteratorCallable(callable $callable): SessionFunctionsInterface |
|
301 | |||
302 | /** |
||
303 | * @inheritdoc |
||
304 | */ |
||
305 | 1 | public function getAbortCallable(): callable |
|
309 | |||
310 | /** |
||
311 | * @inheritdoc |
||
312 | */ |
||
313 | 3 | public function setAbortCallable(callable $callable): SessionFunctionsInterface |
|
319 | |||
320 | /** |
||
321 | * @inheritdoc |
||
322 | */ |
||
323 | 1 | public function getCacheExpireCallable(): callable |
|
327 | |||
328 | /** |
||
329 | * @inheritdoc |
||
330 | */ |
||
331 | 3 | public function setCacheExpireCallable(callable $callable): SessionFunctionsInterface |
|
337 | |||
338 | /** |
||
339 | * @inheritdoc |
||
340 | */ |
||
341 | 1 | public function getCacheLimiterCallable(): callable |
|
345 | |||
346 | /** |
||
347 | * @inheritdoc |
||
348 | */ |
||
349 | 3 | public function setCacheLimiterCallable(callable $callable): SessionFunctionsInterface |
|
355 | |||
356 | /** |
||
357 | * @inheritdoc |
||
358 | */ |
||
359 | 1 | public function getCreateIdCallable(): callable |
|
363 | |||
364 | /** |
||
365 | * @inheritdoc |
||
366 | */ |
||
367 | 3 | public function setCreateIdCallable(callable $callable): SessionFunctionsInterface |
|
373 | |||
374 | /** |
||
375 | * @inheritdoc |
||
376 | */ |
||
377 | 1 | public function getDecodeCallable(): callable |
|
381 | |||
382 | /** |
||
383 | * @inheritdoc |
||
384 | */ |
||
385 | 3 | public function setDecodeCallable(callable $callable): SessionFunctionsInterface |
|
391 | |||
392 | /** |
||
393 | * @inheritdoc |
||
394 | */ |
||
395 | 1 | public function getDestroyCallable(): callable |
|
399 | |||
400 | /** |
||
401 | * @inheritdoc |
||
402 | */ |
||
403 | 3 | public function setDestroyCallable(callable $callable): SessionFunctionsInterface |
|
409 | |||
410 | /** |
||
411 | * @inheritdoc |
||
412 | */ |
||
413 | 1 | public function getEncodeCallable(): callable |
|
417 | |||
418 | /** |
||
419 | * @inheritdoc |
||
420 | */ |
||
421 | 3 | public function setEncodeCallable(callable $callable): SessionFunctionsInterface |
|
427 | |||
428 | /** |
||
429 | * @inheritdoc |
||
430 | */ |
||
431 | 1 | public function getGcCallable(): callable |
|
435 | |||
436 | /** |
||
437 | * @inheritdoc |
||
438 | */ |
||
439 | 3 | public function setGcCallable(callable $callable): SessionFunctionsInterface |
|
445 | |||
446 | /** |
||
447 | * @inheritdoc |
||
448 | */ |
||
449 | 1 | public function getGetCookieParamsCallable(): callable |
|
453 | |||
454 | /** |
||
455 | * @inheritdoc |
||
456 | */ |
||
457 | 3 | public function setGetCookieParamsCallable(callable $callable): SessionFunctionsInterface |
|
463 | |||
464 | /** |
||
465 | * @inheritdoc |
||
466 | */ |
||
467 | 1 | public function getIdCallable(): callable |
|
471 | |||
472 | /** |
||
473 | * @inheritdoc |
||
474 | */ |
||
475 | 3 | public function setIdCallable(callable $callable): SessionFunctionsInterface |
|
481 | |||
482 | /** |
||
483 | * @inheritdoc |
||
484 | */ |
||
485 | 1 | public function getModuleNameCallable(): callable |
|
489 | |||
490 | /** |
||
491 | * @inheritdoc |
||
492 | */ |
||
493 | 3 | public function setModuleNameCallable(callable $callable): SessionFunctionsInterface |
|
499 | |||
500 | /** |
||
501 | * @inheritdoc |
||
502 | */ |
||
503 | 1 | public function getNameCallable(): callable |
|
507 | |||
508 | /** |
||
509 | * @inheritdoc |
||
510 | */ |
||
511 | 3 | public function setNameCallable(callable $callable): SessionFunctionsInterface |
|
517 | |||
518 | /** |
||
519 | * @inheritdoc |
||
520 | */ |
||
521 | 1 | public function getRegenerateIdCallable(): callable |
|
525 | |||
526 | /** |
||
527 | * @inheritdoc |
||
528 | */ |
||
529 | 3 | public function setRegenerateIdCallable(callable $callable): SessionFunctionsInterface |
|
535 | |||
536 | /** |
||
537 | * @inheritdoc |
||
538 | */ |
||
539 | 1 | public function getRegisterShutdownCallable(): callable |
|
543 | |||
544 | /** |
||
545 | * @inheritdoc |
||
546 | */ |
||
547 | 3 | public function setRegisterShutdownCallable(callable $callable): SessionFunctionsInterface |
|
553 | |||
554 | /** |
||
555 | * @inheritdoc |
||
556 | */ |
||
557 | 1 | public function getResetCallable(): callable |
|
561 | |||
562 | /** |
||
563 | * @inheritdoc |
||
564 | */ |
||
565 | 3 | public function setResetCallable(callable $callable): SessionFunctionsInterface |
|
571 | |||
572 | /** |
||
573 | * @inheritdoc |
||
574 | */ |
||
575 | 1 | public function getSavePathCallable(): callable |
|
579 | |||
580 | /** |
||
581 | * @inheritdoc |
||
582 | */ |
||
583 | 3 | public function setSavePathCallable(callable $callable): SessionFunctionsInterface |
|
589 | |||
590 | /** |
||
591 | * @inheritdoc |
||
592 | */ |
||
593 | 1 | public function getSetCookieParamsCallable(): callable |
|
597 | |||
598 | /** |
||
599 | * @inheritdoc |
||
600 | */ |
||
601 | 3 | public function setSetCookieParamsCallable(callable $callable): SessionFunctionsInterface |
|
607 | |||
608 | /** |
||
609 | * @inheritdoc |
||
610 | */ |
||
611 | 1 | public function getSetSaveHandlerCallable(): callable |
|
615 | |||
616 | /** |
||
617 | * @inheritdoc |
||
618 | */ |
||
619 | 3 | public function setSetSaveHandlerCallable(callable $callable): SessionFunctionsInterface |
|
625 | |||
626 | /** |
||
627 | * @inheritdoc |
||
628 | */ |
||
629 | 2 | public function getStartCallable(): callable |
|
633 | |||
634 | /** |
||
635 | * @inheritdoc |
||
636 | */ |
||
637 | 3 | public function setStartCallable(callable $callable): SessionFunctionsInterface |
|
643 | |||
644 | /** |
||
645 | * @inheritdoc |
||
646 | */ |
||
647 | 1 | public function getStatusCallable(): callable |
|
651 | |||
652 | /** |
||
653 | * @inheritdoc |
||
654 | */ |
||
655 | 3 | public function setStatusCallable(callable $callable): SessionFunctionsInterface |
|
661 | |||
662 | /** |
||
663 | * @inheritdoc |
||
664 | */ |
||
665 | 1 | public function getUnsetCallable(): callable |
|
669 | |||
670 | /** |
||
671 | * @inheritdoc |
||
672 | */ |
||
673 | 3 | public function setUnsetCallable(callable $callable): SessionFunctionsInterface |
|
679 | |||
680 | /** |
||
681 | * @inheritdoc |
||
682 | */ |
||
683 | 2 | public function getWriteCloseCallable(): callable |
|
687 | |||
688 | /** |
||
689 | * @inheritdoc |
||
690 | */ |
||
691 | 3 | public function setWriteCloseCallable(callable $callable): SessionFunctionsInterface |
|
697 | } |
||
698 |