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 declare(strict_types=1); |
||
| 36 | class SessionFunctions implements SessionFunctionsInterface |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * @var callable |
||
| 40 | */ |
||
| 41 | private $retrieveCallable; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var callable |
||
| 45 | */ |
||
| 46 | private $putCallable; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var callable |
||
| 50 | */ |
||
| 51 | private $hasCallable; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var callable |
||
| 55 | */ |
||
| 56 | private $deleteCallable; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var callable |
||
| 60 | */ |
||
| 61 | private $iteratorCallable; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var callable |
||
| 65 | */ |
||
| 66 | private $abortCallable; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var callable |
||
| 70 | */ |
||
| 71 | private $cacheLimiterCallable; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var callable |
||
| 75 | */ |
||
| 76 | private $createIdCallable; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var callable |
||
| 80 | */ |
||
| 81 | private $writeCloseCallable; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var callable |
||
| 85 | */ |
||
| 86 | private $unsetCallable; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var callable |
||
| 90 | */ |
||
| 91 | private $statusCallable; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var callable |
||
| 95 | */ |
||
| 96 | private $startCallable; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var callable |
||
| 100 | */ |
||
| 101 | private $setSaveHandlerCallable; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var callable |
||
| 105 | */ |
||
| 106 | private $setCookieParamsCallable; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var callable |
||
| 110 | */ |
||
| 111 | private $savePathCallable; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var callable |
||
| 115 | */ |
||
| 116 | private $resetCallable; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var callable |
||
| 120 | */ |
||
| 121 | private $registerShutdownCallable; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var callable |
||
| 125 | */ |
||
| 126 | private $regenerateIdCallable; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var callable |
||
| 130 | */ |
||
| 131 | private $nameCallable; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var callable |
||
| 135 | */ |
||
| 136 | private $moduleNameCallable; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @var callable |
||
| 140 | */ |
||
| 141 | private $decodeCallable; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var callable |
||
| 145 | */ |
||
| 146 | private $destroyCallable; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var callable |
||
| 150 | */ |
||
| 151 | private $encodeCallable; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var callable |
||
| 155 | */ |
||
| 156 | private $gcCallable; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var callable |
||
| 160 | */ |
||
| 161 | private $getCookieParamsCallable; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var callable |
||
| 165 | */ |
||
| 166 | private $idCallable; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @var callable |
||
| 170 | */ |
||
| 171 | private $cacheExpireCallable; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var callable |
||
| 175 | */ |
||
| 176 | 3 | private $couldBeStartedCallable; |
|
| 177 | |||
| 178 | /** |
||
| 179 | * Constructor. |
||
| 180 | 1 | */ |
|
| 181 | 3 | public function __construct() |
|
| 225 | |||
| 226 | 1 | /** |
|
| 227 | * @inheritdoc |
||
| 228 | */ |
||
| 229 | public function getRetrieveCallable(): callable |
||
| 233 | |||
| 234 | 3 | /** |
|
| 235 | * @inheritdoc |
||
| 236 | 3 | */ |
|
| 237 | public function setRetrieveCallable(callable $callable): SessionFunctionsInterface |
||
| 238 | { |
||
| 239 | $this->retrieveCallable = $callable; |
||
| 240 | |||
| 241 | return $this; |
||
| 242 | 1 | } |
|
| 243 | |||
| 244 | 1 | /** |
|
| 245 | * @inheritdoc |
||
| 246 | */ |
||
| 247 | public function getPutCallable(): callable |
||
| 251 | |||
| 252 | 3 | /** |
|
| 253 | * @inheritdoc |
||
| 254 | 3 | */ |
|
| 255 | public function setPutCallable(callable $callable): SessionFunctionsInterface |
||
| 256 | { |
||
| 257 | $this->putCallable = $callable; |
||
| 258 | |||
| 259 | return $this; |
||
| 260 | 1 | } |
|
| 261 | |||
| 262 | 1 | /** |
|
| 263 | * @inheritdoc |
||
| 264 | */ |
||
| 265 | public function getHasCallable(): callable |
||
| 269 | |||
| 270 | 3 | /** |
|
| 271 | * @inheritdoc |
||
| 272 | 3 | */ |
|
| 273 | public function setHasCallable(callable $callable): SessionFunctionsInterface |
||
| 274 | { |
||
| 275 | $this->hasCallable = $callable; |
||
| 276 | |||
| 277 | return $this; |
||
| 278 | 1 | } |
|
| 279 | |||
| 280 | 1 | /** |
|
| 281 | * @inheritdoc |
||
| 282 | */ |
||
| 283 | public function getDeleteCallable(): callable |
||
| 287 | |||
| 288 | 3 | /** |
|
| 289 | * @inheritdoc |
||
| 290 | 3 | */ |
|
| 291 | public function setDeleteCallable(callable $callable): SessionFunctionsInterface |
||
| 292 | { |
||
| 293 | $this->deleteCallable = $callable; |
||
| 294 | |||
| 295 | return $this; |
||
| 296 | 1 | } |
|
| 297 | |||
| 298 | 1 | /** |
|
| 299 | * @inheritdoc |
||
| 300 | */ |
||
| 301 | public function getIteratorCallable(): callable |
||
| 305 | |||
| 306 | 3 | /** |
|
| 307 | * @inheritdoc |
||
| 308 | 3 | */ |
|
| 309 | public function setIteratorCallable(callable $callable): SessionFunctionsInterface |
||
| 310 | { |
||
| 311 | $this->iteratorCallable = $callable; |
||
| 312 | |||
| 313 | return $this; |
||
| 314 | 1 | } |
|
| 315 | |||
| 316 | 1 | /** |
|
| 317 | * @inheritdoc |
||
| 318 | */ |
||
| 319 | public function getAbortCallable(): callable |
||
| 323 | |||
| 324 | 3 | /** |
|
| 325 | * @inheritdoc |
||
| 326 | 3 | */ |
|
| 327 | public function setAbortCallable(callable $callable): SessionFunctionsInterface |
||
| 328 | { |
||
| 329 | $this->abortCallable = $callable; |
||
| 330 | |||
| 331 | return $this; |
||
| 332 | 1 | } |
|
| 333 | |||
| 334 | 1 | /** |
|
| 335 | * @inheritdoc |
||
| 336 | */ |
||
| 337 | public function getCacheExpireCallable(): callable |
||
| 341 | |||
| 342 | 3 | /** |
|
| 343 | * @inheritdoc |
||
| 344 | 3 | */ |
|
| 345 | public function setCacheExpireCallable(callable $callable): SessionFunctionsInterface |
||
| 346 | { |
||
| 347 | $this->cacheExpireCallable = $callable; |
||
| 348 | |||
| 349 | return $this; |
||
| 350 | 1 | } |
|
| 351 | |||
| 352 | 1 | /** |
|
| 353 | * @inheritdoc |
||
| 354 | */ |
||
| 355 | public function getCacheLimiterCallable(): callable |
||
| 359 | |||
| 360 | 3 | /** |
|
| 361 | * @inheritdoc |
||
| 362 | 3 | */ |
|
| 363 | public function setCacheLimiterCallable(callable $callable): SessionFunctionsInterface |
||
| 364 | { |
||
| 365 | $this->cacheLimiterCallable = $callable; |
||
| 366 | |||
| 367 | return $this; |
||
| 368 | 1 | } |
|
| 369 | |||
| 370 | 1 | /** |
|
| 371 | * @inheritdoc |
||
| 372 | */ |
||
| 373 | public function getCreateIdCallable(): callable |
||
| 377 | |||
| 378 | 3 | /** |
|
| 379 | * @inheritdoc |
||
| 380 | 3 | */ |
|
| 381 | public function setCreateIdCallable(callable $callable): SessionFunctionsInterface |
||
| 382 | { |
||
| 383 | $this->createIdCallable = $callable; |
||
| 384 | |||
| 385 | return $this; |
||
| 386 | 1 | } |
|
| 387 | |||
| 388 | 1 | /** |
|
| 389 | * @inheritdoc |
||
| 390 | */ |
||
| 391 | public function getDecodeCallable(): callable |
||
| 395 | |||
| 396 | 3 | /** |
|
| 397 | * @inheritdoc |
||
| 398 | 3 | */ |
|
| 399 | public function setDecodeCallable(callable $callable): SessionFunctionsInterface |
||
| 400 | { |
||
| 401 | $this->decodeCallable = $callable; |
||
| 402 | |||
| 403 | return $this; |
||
| 404 | 1 | } |
|
| 405 | |||
| 406 | 1 | /** |
|
| 407 | * @inheritdoc |
||
| 408 | */ |
||
| 409 | public function getDestroyCallable(): callable |
||
| 413 | |||
| 414 | 3 | /** |
|
| 415 | * @inheritdoc |
||
| 416 | 3 | */ |
|
| 417 | public function setDestroyCallable(callable $callable): SessionFunctionsInterface |
||
| 418 | { |
||
| 419 | $this->destroyCallable = $callable; |
||
| 420 | |||
| 421 | return $this; |
||
| 422 | 1 | } |
|
| 423 | |||
| 424 | 1 | /** |
|
| 425 | * @inheritdoc |
||
| 426 | */ |
||
| 427 | public function getEncodeCallable(): callable |
||
| 431 | |||
| 432 | 3 | /** |
|
| 433 | * @inheritdoc |
||
| 434 | 3 | */ |
|
| 435 | public function setEncodeCallable(callable $callable): SessionFunctionsInterface |
||
| 436 | { |
||
| 437 | $this->encodeCallable = $callable; |
||
| 438 | |||
| 439 | return $this; |
||
| 440 | 1 | } |
|
| 441 | |||
| 442 | 1 | /** |
|
| 443 | * @inheritdoc |
||
| 444 | */ |
||
| 445 | public function getGcCallable(): callable |
||
| 449 | |||
| 450 | 3 | /** |
|
| 451 | * @inheritdoc |
||
| 452 | 3 | */ |
|
| 453 | public function setGcCallable(callable $callable): SessionFunctionsInterface |
||
| 454 | { |
||
| 455 | $this->gcCallable = $callable; |
||
| 456 | |||
| 457 | return $this; |
||
| 458 | 1 | } |
|
| 459 | |||
| 460 | 1 | /** |
|
| 461 | * @inheritdoc |
||
| 462 | */ |
||
| 463 | public function getGetCookieParamsCallable(): callable |
||
| 467 | |||
| 468 | 3 | /** |
|
| 469 | * @inheritdoc |
||
| 470 | 3 | */ |
|
| 471 | public function setGetCookieParamsCallable(callable $callable): SessionFunctionsInterface |
||
| 472 | { |
||
| 473 | $this->getCookieParamsCallable = $callable; |
||
| 474 | |||
| 475 | return $this; |
||
| 476 | 1 | } |
|
| 477 | |||
| 478 | 1 | /** |
|
| 479 | * @inheritdoc |
||
| 480 | */ |
||
| 481 | public function getIdCallable(): callable |
||
| 485 | |||
| 486 | 3 | /** |
|
| 487 | * @inheritdoc |
||
| 488 | 3 | */ |
|
| 489 | public function setIdCallable(callable $callable): SessionFunctionsInterface |
||
| 490 | { |
||
| 491 | $this->idCallable = $callable; |
||
| 492 | |||
| 493 | return $this; |
||
| 494 | 1 | } |
|
| 495 | |||
| 496 | 1 | /** |
|
| 497 | * @inheritdoc |
||
| 498 | */ |
||
| 499 | public function getModuleNameCallable(): callable |
||
| 503 | |||
| 504 | 3 | /** |
|
| 505 | * @inheritdoc |
||
| 506 | 3 | */ |
|
| 507 | public function setModuleNameCallable(callable $callable): SessionFunctionsInterface |
||
| 508 | { |
||
| 509 | $this->moduleNameCallable = $callable; |
||
| 510 | |||
| 511 | return $this; |
||
| 512 | 1 | } |
|
| 513 | |||
| 514 | 1 | /** |
|
| 515 | * @inheritdoc |
||
| 516 | */ |
||
| 517 | public function getNameCallable(): callable |
||
| 521 | |||
| 522 | 3 | /** |
|
| 523 | * @inheritdoc |
||
| 524 | 3 | */ |
|
| 525 | public function setNameCallable(callable $callable): SessionFunctionsInterface |
||
| 526 | { |
||
| 527 | $this->nameCallable = $callable; |
||
| 528 | |||
| 529 | return $this; |
||
| 530 | 1 | } |
|
| 531 | |||
| 532 | 1 | /** |
|
| 533 | * @inheritdoc |
||
| 534 | */ |
||
| 535 | public function getRegenerateIdCallable(): callable |
||
| 539 | |||
| 540 | 3 | /** |
|
| 541 | * @inheritdoc |
||
| 542 | 3 | */ |
|
| 543 | public function setRegenerateIdCallable(callable $callable): SessionFunctionsInterface |
||
| 544 | { |
||
| 545 | $this->regenerateIdCallable = $callable; |
||
| 546 | |||
| 547 | return $this; |
||
| 548 | 1 | } |
|
| 549 | |||
| 550 | 1 | /** |
|
| 551 | * @inheritdoc |
||
| 552 | */ |
||
| 553 | public function getRegisterShutdownCallable(): callable |
||
| 557 | |||
| 558 | 3 | /** |
|
| 559 | * @inheritdoc |
||
| 560 | 3 | */ |
|
| 561 | public function setRegisterShutdownCallable(callable $callable): SessionFunctionsInterface |
||
| 562 | { |
||
| 563 | $this->registerShutdownCallable = $callable; |
||
| 564 | |||
| 565 | return $this; |
||
| 566 | 1 | } |
|
| 567 | |||
| 568 | 1 | /** |
|
| 569 | * @inheritdoc |
||
| 570 | */ |
||
| 571 | public function getResetCallable(): callable |
||
| 575 | |||
| 576 | 3 | /** |
|
| 577 | * @inheritdoc |
||
| 578 | 3 | */ |
|
| 579 | public function setResetCallable(callable $callable): SessionFunctionsInterface |
||
| 580 | { |
||
| 581 | $this->resetCallable = $callable; |
||
| 582 | |||
| 583 | return $this; |
||
| 584 | 1 | } |
|
| 585 | |||
| 586 | 1 | /** |
|
| 587 | * @inheritdoc |
||
| 588 | */ |
||
| 589 | public function getSavePathCallable(): callable |
||
| 593 | |||
| 594 | 3 | /** |
|
| 595 | * @inheritdoc |
||
| 596 | 3 | */ |
|
| 597 | public function setSavePathCallable(callable $callable): SessionFunctionsInterface |
||
| 598 | { |
||
| 599 | $this->savePathCallable = $callable; |
||
| 600 | |||
| 601 | return $this; |
||
| 602 | 1 | } |
|
| 603 | |||
| 604 | 1 | /** |
|
| 605 | * @inheritdoc |
||
| 606 | */ |
||
| 607 | public function getSetCookieParamsCallable(): callable |
||
| 611 | |||
| 612 | 3 | /** |
|
| 613 | * @inheritdoc |
||
| 614 | 3 | */ |
|
| 615 | public function setSetCookieParamsCallable(callable $callable): SessionFunctionsInterface |
||
| 616 | { |
||
| 617 | $this->setCookieParamsCallable = $callable; |
||
| 618 | |||
| 619 | return $this; |
||
| 620 | 1 | } |
|
| 621 | |||
| 622 | 1 | /** |
|
| 623 | * @inheritdoc |
||
| 624 | */ |
||
| 625 | public function getSetSaveHandlerCallable(): callable |
||
| 629 | |||
| 630 | 3 | /** |
|
| 631 | * @inheritdoc |
||
| 632 | 3 | */ |
|
| 633 | public function setSetSaveHandlerCallable(callable $callable): SessionFunctionsInterface |
||
| 634 | { |
||
| 635 | $this->setSaveHandlerCallable = $callable; |
||
| 636 | |||
| 637 | return $this; |
||
| 638 | 2 | } |
|
| 639 | |||
| 640 | 2 | /** |
|
| 641 | * @inheritdoc |
||
| 642 | */ |
||
| 643 | public function getStartCallable(): callable |
||
| 647 | |||
| 648 | 3 | /** |
|
| 649 | * @inheritdoc |
||
| 650 | 3 | */ |
|
| 651 | public function setStartCallable(callable $callable): SessionFunctionsInterface |
||
| 652 | { |
||
| 653 | $this->startCallable = $callable; |
||
| 654 | |||
| 655 | return $this; |
||
| 656 | 1 | } |
|
| 657 | |||
| 658 | 1 | /** |
|
| 659 | * @inheritdoc |
||
| 660 | */ |
||
| 661 | public function getStatusCallable(): callable |
||
| 665 | |||
| 666 | 3 | /** |
|
| 667 | * @inheritdoc |
||
| 668 | 3 | */ |
|
| 669 | public function setStatusCallable(callable $callable): SessionFunctionsInterface |
||
| 670 | { |
||
| 671 | $this->statusCallable = $callable; |
||
| 672 | |||
| 673 | return $this; |
||
| 674 | 1 | } |
|
| 675 | |||
| 676 | 1 | /** |
|
| 677 | * @inheritdoc |
||
| 678 | */ |
||
| 679 | public function getUnsetCallable(): callable |
||
| 683 | |||
| 684 | 3 | /** |
|
| 685 | * @inheritdoc |
||
| 686 | 3 | */ |
|
| 687 | public function setUnsetCallable(callable $callable): SessionFunctionsInterface |
||
| 688 | { |
||
| 689 | $this->unsetCallable = $callable; |
||
| 690 | |||
| 691 | return $this; |
||
| 692 | 2 | } |
|
| 693 | |||
| 694 | 2 | /** |
|
| 695 | * @inheritdoc |
||
| 696 | */ |
||
| 697 | public function getWriteCloseCallable(): callable |
||
| 701 | |||
| 702 | 3 | /** |
|
| 703 | * @inheritdoc |
||
| 704 | 3 | */ |
|
| 705 | public function setWriteCloseCallable(callable $callable): SessionFunctionsInterface |
||
| 706 | { |
||
| 707 | $this->writeCloseCallable = $callable; |
||
| 708 | |||
| 709 | return $this; |
||
| 710 | 1 | } |
|
| 711 | |||
| 712 | 1 | /** |
|
| 713 | * @inheritdoc |
||
| 714 | */ |
||
| 715 | public function getCouldBeStartedCallable(): callable |
||
| 719 | |||
| 720 | 3 | /** |
|
| 721 | * @inheritdoc |
||
| 722 | 3 | */ |
|
| 723 | public function setCouldBeStartedCallable(callable $callable): SessionFunctionsInterface |
||
| 724 | { |
||
| 725 | $this->couldBeStartedCallable = $callable; |
||
| 726 | |||
| 727 | return $this; |
||
| 728 | } |
||
| 729 | } |
||
| 730 |