Completed
Push — master ( 32e652...8e829c )
by Neomerx
11:56
created

SessionFunctions   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 667
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 667
c 0
b 0
f 0
wmc 55
lcom 0
cbo 0
rs 5.196

55 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 41 1
A getRetrieveCallable() 0 4 1
A setRetrieveCallable() 0 6 1
A getPutCallable() 0 4 1
A setPutCallable() 0 6 1
A getHasCallable() 0 4 1
A setHasCallable() 0 6 1
A getDeleteCallable() 0 4 1
A setDeleteCallable() 0 6 1
A getIteratorCallable() 0 4 1
A setIteratorCallable() 0 6 1
A getAbortCallable() 0 4 1
A setAbortCallable() 0 6 1
A getCacheExpireCallable() 0 4 1
A setCacheExpireCallable() 0 6 1
A getCacheLimiterCallable() 0 4 1
A setCacheLimiterCallable() 0 6 1
A getCreateIdCallable() 0 4 1
A setCreateIdCallable() 0 6 1
A getDecodeCallable() 0 4 1
A setDecodeCallable() 0 6 1
A getDestroyCallable() 0 4 1
A setDestroyCallable() 0 6 1
A getEncodeCallable() 0 4 1
A setEncodeCallable() 0 6 1
A getGcCallable() 0 4 1
A setGcCallable() 0 6 1
A getGetCookieParamsCallable() 0 4 1
A setGetCookieParamsCallable() 0 6 1
A getIdCallable() 0 4 1
A setIdCallable() 0 6 1
A getModuleNameCallable() 0 4 1
A setModuleNameCallable() 0 6 1
A getNameCallable() 0 4 1
A setNameCallable() 0 6 1
A getRegenerateIdCallable() 0 4 1
A setRegenerateIdCallable() 0 6 1
A getRegisterShutdownCallable() 0 4 1
A setRegisterShutdownCallable() 0 6 1
A getResetCallable() 0 4 1
A setResetCallable() 0 6 1
A getSavePathCallable() 0 4 1
A setSavePathCallable() 0 6 1
A getSetCookieParamsCallable() 0 4 1
A setSetCookieParamsCallable() 0 6 1
A getSetSaveHandlerCallable() 0 4 1
A setSetSaveHandlerCallable() 0 6 1
A getStartCallable() 0 4 1
A setStartCallable() 0 6 1
A getStatusCallable() 0 4 1
A setStatusCallable() 0 6 1
A getUnsetCallable() 0 4 1
A setUnsetCallable() 0 6 1
A getWriteCloseCallable() 0 4 1
A setWriteCloseCallable() 0 6 1

How to fix   Complexity   

Complex Class

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;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use ArrayIterator;
20
use Iterator;
21
use Limoncello\Application\Contracts\Session\SessionFunctionsInterface;
22
23
/**
24
 * @package Limoncello\Application
25
 */
26
class SessionFunctions implements SessionFunctionsInterface
27
{
28
    /**
29
     * @var callable
30
     */
31
    private $retrieveCallable;
32
33
    /**
34
     * @var callable
35
     */
36
    private $putCallable;
37
38
    /**
39
     * @var callable
40
     */
41
    private $hasCallable;
42
43
    /**
44
     * @var callable
45
     */
46
    private $deleteCallable;
47
48
    /**
49
     * @var callable
50
     */
51
    private $iteratorCallable;
52
53
    /**
54
     * @var callable
55
     */
56
    private $abortCallable;
57
58
    /**
59
     * @var callable
60
     */
61
    private $cacheLimiterCallable;
62
63
    /**
64
     * @var callable
65
     */
66
    private $createIdCallable;
67
68
    /**
69
     * @var callable
70
     */
71
    private $writeCloseCallable;
72
73
    /**
74
     * @var callable
75
     */
76
    private $unsetCallable;
77
78
    /**
79
     * @var callable
80
     */
81
    private $statusCallable;
82
83
    /**
84
     * @var callable
85
     */
86
    private $startCallable;
87
88
    /**
89
     * @var callable
90
     */
91
    private $setSaveHandlerCallable;
92
93
    /**
94
     * @var callable
95
     */
96
    private $setCookieParamsCallable;
97
98
    /**
99
     * @var callable
100
     */
101
    private $savePathCallable;
102
103
    /**
104
     * @var callable
105
     */
106
    private $resetCallable;
107
108
    /**
109
     * @var callable
110
     */
111
    private $registerShutdownCallable;
112
113
    /**
114
     * @var callable
115
     */
116
    private $regenerateIdCallable;
117
118
    /**
119
     * @var callable
120
     */
121
    private $nameCallable;
122
123
    /**
124
     * @var callable
125
     */
126
    private $moduleNameCallable;
127
128
    /**
129
     * @var callable
130
     */
131
    private $decodeCallable;
132
133
    /**
134
     * @var callable
135
     */
136
    private $destroyCallable;
137
138
    /**
139
     * @var callable
140
     */
141
    private $encodeCallable;
142
143
    /**
144
     * @var callable
145
     */
146
    private $gcCallable;
147
148
    /**
149
     * @var callable
150
     */
151
    private $getCookieParamsCallable;
152
153
    /**
154
     * @var callable
155
     */
156
    private $idCallable;
157
    /**
158
     * @var callable
159
     */
160
    private $cacheExpireCallable;
161
162
    /**
163
     * Constructor.
164
     */
165
    public function __construct()
166
    {
167
        $this
168
            ->setRetrieveCallable(function (string $key) {
169
                return $_SESSION[$key];
170
            })
171
            ->setPutCallable(function (string $key, $serializable): void {
172
                $_SESSION[$key] = $serializable;
173
            })
174
            ->setHasCallable(function (string $key): bool {
175
                return array_key_exists($key, $_SESSION);
176
            })
177
            ->setDeleteCallable(function (string $key): void {
178
                unset($_SESSION[$key]);
179
            })
180
            ->setIteratorCallable(function (): Iterator {
181
                return new ArrayIterator($_SESSION);
182
            })
183
            ->setAbortCallable('\session_abort')
184
            ->setCacheLimiterCallable('\session_cache_limiter')
185
            ->setCreateIdCallable('\session_create_id')
186
            ->setWriteCloseCallable('\session_write_close')
187
            ->setUnsetCallable('\session_unset')
188
            ->setStatusCallable('\session_status')
189
            ->setStartCallable('\session_start')
190
            ->setSetSaveHandlerCallable('\session_set_save_handler')
191
            ->setSetCookieParamsCallable('\session_set_cookie_params')
192
            ->setSavePathCallable('\session_save_path')
193
            ->setResetCallable('\session_reset')
194
            ->setRegisterShutdownCallable('\session_register_shutdown')
195
            ->setRegenerateIdCallable('\session_regenerate_id')
196
            ->setNameCallable('\session_name')
197
            ->setModuleNameCallable('\session_module_name')
198
            ->setDecodeCallable('\session_decode')
199
            ->setDestroyCallable('\session_destroy')
200
            ->setEncodeCallable('\session_encode')
201
            ->setGcCallable('\session_gc')
202
            ->setGetCookieParamsCallable('\session_get_cookie_params')
203
            ->setIdCallable('\session_id')
204
            ->setCacheExpireCallable('\session_cache_expire');
205
    }
206
207
    /**
208
     * @inheritdoc
209
     */
210
    public function getRetrieveCallable(): callable
211
    {
212
        return $this->retrieveCallable;
213
    }
214
215
    /**
216
     * @inheritdoc
217
     */
218
    public function setRetrieveCallable(callable $callable): SessionFunctionsInterface
219
    {
220
        $this->retrieveCallable = $callable;
221
222
        return $this;
223
    }
224
225
    /**
226
     * @inheritdoc
227
     */
228
    public function getPutCallable(): callable
229
    {
230
        return $this->putCallable;
231
    }
232
233
    /**
234
     * @inheritdoc
235
     */
236
    public function setPutCallable(callable $callable): SessionFunctionsInterface
237
    {
238
        $this->putCallable = $callable;
239
240
        return $this;
241
    }
242
243
    /**
244
     * @inheritdoc
245
     */
246
    public function getHasCallable(): callable
247
    {
248
        return $this->hasCallable;
249
    }
250
251
    /**
252
     * @inheritdoc
253
     */
254
    public function setHasCallable(callable $callable): SessionFunctionsInterface
255
    {
256
        $this->hasCallable = $callable;
257
258
        return $this;
259
    }
260
261
    /**
262
     * @inheritdoc
263
     */
264
    public function getDeleteCallable(): callable
265
    {
266
        return $this->deleteCallable;
267
    }
268
269
    /**
270
     * @inheritdoc
271
     */
272
    public function setDeleteCallable(callable $callable): SessionFunctionsInterface
273
    {
274
        $this->deleteCallable = $callable;
275
276
        return $this;
277
    }
278
279
    /**
280
     * @inheritdoc
281
     */
282
    public function getIteratorCallable(): callable
283
    {
284
        return $this->iteratorCallable;
285
    }
286
287
    /**
288
     * @inheritdoc
289
     */
290
    public function setIteratorCallable(callable $callable): SessionFunctionsInterface
291
    {
292
        $this->iteratorCallable = $callable;
293
294
        return $this;
295
    }
296
297
    /**
298
     * @inheritdoc
299
     */
300
    public function getAbortCallable(): callable
301
    {
302
        return $this->abortCallable;
303
    }
304
305
    /**
306
     * @inheritdoc
307
     */
308
    public function setAbortCallable(callable $callable): SessionFunctionsInterface
309
    {
310
        $this->abortCallable = $callable;
311
312
        return $this;
313
    }
314
315
    /**
316
     * @inheritdoc
317
     */
318
    public function getCacheExpireCallable(): callable
319
    {
320
        return $this->cacheExpireCallable;
321
    }
322
323
    /**
324
     * @inheritdoc
325
     */
326
    public function setCacheExpireCallable(callable $callable): SessionFunctionsInterface
327
    {
328
        $this->cacheExpireCallable = $callable;
329
330
        return $this;
331
    }
332
333
    /**
334
     * @inheritdoc
335
     */
336
    public function getCacheLimiterCallable(): callable
337
    {
338
        return $this->cacheLimiterCallable;
339
    }
340
341
    /**
342
     * @inheritdoc
343
     */
344
    public function setCacheLimiterCallable(callable $callable): SessionFunctionsInterface
345
    {
346
        $this->cacheLimiterCallable = $callable;
347
348
        return $this;
349
    }
350
351
    /**
352
     * @inheritdoc
353
     */
354
    public function getCreateIdCallable(): callable
355
    {
356
        return $this->createIdCallable;
357
    }
358
359
    /**
360
     * @inheritdoc
361
     */
362
    public function setCreateIdCallable(callable $callable): SessionFunctionsInterface
363
    {
364
        $this->createIdCallable = $callable;
365
366
        return $this;
367
    }
368
369
    /**
370
     * @inheritdoc
371
     */
372
    public function getDecodeCallable(): callable
373
    {
374
        return $this->decodeCallable;
375
    }
376
377
    /**
378
     * @inheritdoc
379
     */
380
    public function setDecodeCallable(callable $callable): SessionFunctionsInterface
381
    {
382
        $this->decodeCallable = $callable;
383
384
        return $this;
385
    }
386
387
    /**
388
     * @inheritdoc
389
     */
390
    public function getDestroyCallable(): callable
391
    {
392
        return $this->destroyCallable;
393
    }
394
395
    /**
396
     * @inheritdoc
397
     */
398
    public function setDestroyCallable(callable $callable): SessionFunctionsInterface
399
    {
400
        $this->destroyCallable = $callable;
401
402
        return $this;
403
    }
404
405
    /**
406
     * @inheritdoc
407
     */
408
    public function getEncodeCallable(): callable
409
    {
410
        return $this->encodeCallable;
411
    }
412
413
    /**
414
     * @inheritdoc
415
     */
416
    public function setEncodeCallable(callable $callable): SessionFunctionsInterface
417
    {
418
        $this->encodeCallable = $callable;
419
420
        return $this;
421
    }
422
423
    /**
424
     * @inheritdoc
425
     */
426
    public function getGcCallable(): callable
427
    {
428
        return $this->gcCallable;
429
    }
430
431
    /**
432
     * @inheritdoc
433
     */
434
    public function setGcCallable(callable $callable): SessionFunctionsInterface
435
    {
436
        $this->gcCallable = $callable;
437
438
        return $this;
439
    }
440
441
    /**
442
     * @inheritdoc
443
     */
444
    public function getGetCookieParamsCallable(): callable
445
    {
446
        return $this->getCookieParamsCallable;
447
    }
448
449
    /**
450
     * @inheritdoc
451
     */
452
    public function setGetCookieParamsCallable(callable $callable): SessionFunctionsInterface
453
    {
454
        $this->getCookieParamsCallable = $callable;
455
456
        return $this;
457
    }
458
459
    /**
460
     * @inheritdoc
461
     */
462
    public function getIdCallable(): callable
463
    {
464
        return $this->idCallable;
465
    }
466
467
    /**
468
     * @inheritdoc
469
     */
470
    public function setIdCallable(callable $callable): SessionFunctionsInterface
471
    {
472
        $this->idCallable = $callable;
473
474
        return $this;
475
    }
476
477
    /**
478
     * @inheritdoc
479
     */
480
    public function getModuleNameCallable(): callable
481
    {
482
        return $this->moduleNameCallable;
483
    }
484
485
    /**
486
     * @inheritdoc
487
     */
488
    public function setModuleNameCallable(callable $callable): SessionFunctionsInterface
489
    {
490
        $this->moduleNameCallable = $callable;
491
492
        return $this;
493
    }
494
495
    /**
496
     * @inheritdoc
497
     */
498
    public function getNameCallable(): callable
499
    {
500
        return $this->nameCallable;
501
    }
502
503
    /**
504
     * @inheritdoc
505
     */
506
    public function setNameCallable(callable $callable): SessionFunctionsInterface
507
    {
508
        $this->nameCallable = $callable;
509
510
        return $this;
511
    }
512
513
    /**
514
     * @inheritdoc
515
     */
516
    public function getRegenerateIdCallable(): callable
517
    {
518
        return $this->regenerateIdCallable;
519
    }
520
521
    /**
522
     * @inheritdoc
523
     */
524
    public function setRegenerateIdCallable(callable $callable): SessionFunctionsInterface
525
    {
526
        $this->regenerateIdCallable = $callable;
527
528
        return $this;
529
    }
530
531
    /**
532
     * @inheritdoc
533
     */
534
    public function getRegisterShutdownCallable(): callable
535
    {
536
        return $this->registerShutdownCallable;
537
    }
538
539
    /**
540
     * @inheritdoc
541
     */
542
    public function setRegisterShutdownCallable(callable $callable): SessionFunctionsInterface
543
    {
544
        $this->registerShutdownCallable = $callable;
545
546
        return $this;
547
    }
548
549
    /**
550
     * @inheritdoc
551
     */
552
    public function getResetCallable(): callable
553
    {
554
        return $this->resetCallable;
555
    }
556
557
    /**
558
     * @inheritdoc
559
     */
560
    public function setResetCallable(callable $callable): SessionFunctionsInterface
561
    {
562
        $this->resetCallable = $callable;
563
564
        return $this;
565
    }
566
567
    /**
568
     * @inheritdoc
569
     */
570
    public function getSavePathCallable(): callable
571
    {
572
        return $this->savePathCallable;
573
    }
574
575
    /**
576
     * @inheritdoc
577
     */
578
    public function setSavePathCallable(callable $callable): SessionFunctionsInterface
579
    {
580
        $this->savePathCallable = $callable;
581
582
        return $this;
583
    }
584
585
    /**
586
     * @inheritdoc
587
     */
588
    public function getSetCookieParamsCallable(): callable
589
    {
590
        return $this->setCookieParamsCallable;
591
    }
592
593
    /**
594
     * @inheritdoc
595
     */
596
    public function setSetCookieParamsCallable(callable $callable): SessionFunctionsInterface
597
    {
598
        $this->setCookieParamsCallable = $callable;
599
600
        return $this;
601
    }
602
603
    /**
604
     * @inheritdoc
605
     */
606
    public function getSetSaveHandlerCallable(): callable
607
    {
608
        return $this->setSaveHandlerCallable;
609
    }
610
611
    /**
612
     * @inheritdoc
613
     */
614
    public function setSetSaveHandlerCallable(callable $callable): SessionFunctionsInterface
615
    {
616
        $this->setSaveHandlerCallable = $callable;
617
618
        return $this;
619
    }
620
621
    /**
622
     * @inheritdoc
623
     */
624
    public function getStartCallable(): callable
625
    {
626
        return $this->startCallable;
627
    }
628
629
    /**
630
     * @inheritdoc
631
     */
632
    public function setStartCallable(callable $callable): SessionFunctionsInterface
633
    {
634
        $this->startCallable = $callable;
635
636
        return $this;
637
    }
638
639
    /**
640
     * @inheritdoc
641
     */
642
    public function getStatusCallable(): callable
643
    {
644
        return $this->statusCallable;
645
    }
646
647
    /**
648
     * @inheritdoc
649
     */
650
    public function setStatusCallable(callable $callable): SessionFunctionsInterface
651
    {
652
        $this->statusCallable = $callable;
653
654
        return $this;
655
    }
656
657
    /**
658
     * @inheritdoc
659
     */
660
    public function getUnsetCallable(): callable
661
    {
662
        return $this->unsetCallable;
663
    }
664
665
    /**
666
     * @inheritdoc
667
     */
668
    public function setUnsetCallable(callable $callable): SessionFunctionsInterface
669
    {
670
        $this->unsetCallable = $callable;
671
672
        return $this;
673
    }
674
675
    /**
676
     * @inheritdoc
677
     */
678
    public function getWriteCloseCallable(): callable
679
    {
680
        return $this->writeCloseCallable;
681
    }
682
683
    /**
684
     * @inheritdoc
685
     */
686
    public function setWriteCloseCallable(callable $callable): SessionFunctionsInterface
687
    {
688
        $this->writeCloseCallable = $callable;
689
690
        return $this;
691
    }
692
}
693