Complex classes like Media 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 Media, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 51 | class Media implements MediaInterface, ArrayableInterface |
||
| 52 | { |
||
| 53 | /** |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | protected $nodeName; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | protected $type; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | protected $url; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var string |
||
| 70 | */ |
||
| 71 | protected $length; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var string |
||
| 75 | */ |
||
| 76 | protected $title; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var string |
||
| 80 | */ |
||
| 81 | protected $description; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var int |
||
| 85 | */ |
||
| 86 | protected $rights; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var int |
||
| 90 | */ |
||
| 91 | protected $titleType; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var int |
||
| 95 | */ |
||
| 96 | protected $descriptionType; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var array |
||
| 100 | */ |
||
| 101 | protected $keywords = array(); |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | protected $comments = array(); |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var array |
||
| 110 | */ |
||
| 111 | protected $responses = array(); |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var array |
||
| 115 | */ |
||
| 116 | protected $backlinks = array(); |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var array |
||
| 120 | */ |
||
| 121 | protected $credits = array(); |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var array |
||
| 125 | */ |
||
| 126 | protected $texts = array(); |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var array |
||
| 130 | */ |
||
| 131 | protected $prices = array(); |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var array |
||
| 135 | */ |
||
| 136 | protected $subTitles = array(); |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @var array |
||
| 140 | */ |
||
| 141 | protected $scenes = array(); |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var MediaContentInterface |
||
| 145 | */ |
||
| 146 | protected $content; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var MediaThumbnailInterface |
||
| 150 | */ |
||
| 151 | protected $thumbnail; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var MediaCategoryInterface |
||
| 155 | */ |
||
| 156 | protected $category; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var MediaHashInterface |
||
| 160 | */ |
||
| 161 | protected $hash; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var MediaEmbedInterface |
||
| 165 | */ |
||
| 166 | protected $embed; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @var MediaLicenseInterface |
||
| 170 | */ |
||
| 171 | protected $license; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var MediaCommunityInterface |
||
| 175 | */ |
||
| 176 | protected $community; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @var MediaRestrictionInterface |
||
| 180 | */ |
||
| 181 | protected $restriction; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @var MediaRatingInterface |
||
| 185 | */ |
||
| 186 | protected $rating; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @var MediaCopyrightInterface |
||
| 190 | */ |
||
| 191 | protected $copyright; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @var MediaPlayerInterface |
||
| 195 | */ |
||
| 196 | protected $player; |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @var MediaStatusInterface |
||
| 200 | */ |
||
| 201 | protected $status; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @var MediaPeerLinkInterface |
||
| 205 | */ |
||
| 206 | protected $peerLink; |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | public function getNodeName() : string |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @param string $nodeName |
||
| 218 | * @return MediaInterface |
||
| 219 | */ |
||
| 220 | 51 | public function setNodeName(string $nodeName) : MediaInterface |
|
| 226 | |||
| 227 | /** |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | 7 | public function getType() : ? string |
|
| 234 | |||
| 235 | /** |
||
| 236 | * @param string $type |
||
| 237 | * @return MediaInterface |
||
| 238 | */ |
||
| 239 | 55 | public function setType(?string $type) : MediaInterface |
|
| 245 | |||
| 246 | /** |
||
| 247 | * @return string |
||
| 248 | */ |
||
| 249 | 10 | public function getUrl() : ? string |
|
| 253 | |||
| 254 | /** |
||
| 255 | * @param string $url |
||
| 256 | * @return MediaInterface |
||
| 257 | */ |
||
| 258 | 54 | public function setUrl(?string $url) : MediaInterface |
|
| 264 | |||
| 265 | /** |
||
| 266 | * @return string |
||
| 267 | */ |
||
| 268 | 3 | public function getLength() : ? string |
|
| 272 | |||
| 273 | /** |
||
| 274 | * @param string $length |
||
| 275 | * @return MediaInterface |
||
| 276 | */ |
||
| 277 | 6 | public function setLength(?string $length) : MediaInterface |
|
| 283 | |||
| 284 | /** |
||
| 285 | * @return string |
||
| 286 | */ |
||
| 287 | 4 | public function getTitle() : ? string |
|
| 291 | |||
| 292 | /** |
||
| 293 | * @param string $title |
||
| 294 | * @return MediaInterface |
||
| 295 | */ |
||
| 296 | 5 | public function setTitle(?string $title) : MediaInterface |
|
| 302 | |||
| 303 | /** |
||
| 304 | * @return string |
||
| 305 | */ |
||
| 306 | 5 | public function getDescription() : ? string |
|
| 310 | |||
| 311 | /** |
||
| 312 | * @param string $description |
||
| 313 | * @return MediaInterface |
||
| 314 | */ |
||
| 315 | 5 | public function setDescription(?string $description) : MediaInterface |
|
| 321 | |||
| 322 | /** |
||
| 323 | * @return string |
||
| 324 | */ |
||
| 325 | 1 | public function getRights() : ?int |
|
| 329 | |||
| 330 | /** |
||
| 331 | * @param int $rights |
||
| 332 | * @return MediaInterface |
||
| 333 | */ |
||
| 334 | 1 | public function setRights(int $rights) : MediaInterface |
|
| 340 | |||
| 341 | /** |
||
| 342 | * @return int |
||
| 343 | */ |
||
| 344 | 2 | public function getTitleType() : ?int |
|
| 348 | |||
| 349 | /** |
||
| 350 | * @param int $titleType |
||
| 351 | * @return MediaInterface |
||
| 352 | */ |
||
| 353 | 4 | public function setTitleType(?int $titleType) : MediaInterface |
|
| 359 | |||
| 360 | |||
| 361 | /** |
||
| 362 | * @return int |
||
| 363 | */ |
||
| 364 | 2 | public function getDescriptionType() : ?int |
|
| 368 | |||
| 369 | /** |
||
| 370 | * @param int $descriptionType |
||
| 371 | * @return MediaInterface |
||
| 372 | */ |
||
| 373 | 5 | public function setDescriptionType(?int $descriptionType) : MediaInterface |
|
| 379 | |||
| 380 | /** |
||
| 381 | * @return array |
||
| 382 | */ |
||
| 383 | 1 | public function getKeywords() : array |
|
| 387 | |||
| 388 | /** |
||
| 389 | * @param array $keywords |
||
| 390 | * @return MediaInterface |
||
| 391 | */ |
||
| 392 | 1 | public function setKeywords(array $keywords) : MediaInterface |
|
| 398 | |||
| 399 | /** |
||
| 400 | * @return array |
||
| 401 | */ |
||
| 402 | 2 | public function getComments() : array |
|
| 406 | |||
| 407 | /** |
||
| 408 | * @param array $comments |
||
| 409 | * @return MediaInterface |
||
| 410 | */ |
||
| 411 | 2 | public function setComments(array $comments) : MediaInterface |
|
| 417 | |||
| 418 | /** |
||
| 419 | * @return array |
||
| 420 | */ |
||
| 421 | 2 | public function getResponses() : array |
|
| 425 | |||
| 426 | /** |
||
| 427 | * @param array $responses |
||
| 428 | * @return MediaInterface |
||
| 429 | */ |
||
| 430 | 2 | public function setResponses(array $responses) : MediaInterface |
|
| 436 | |||
| 437 | /** |
||
| 438 | * @return array |
||
| 439 | */ |
||
| 440 | 2 | public function getBacklinks() : array |
|
| 444 | |||
| 445 | /** |
||
| 446 | * @param array $backlinks |
||
| 447 | * @return MediaInterface |
||
| 448 | */ |
||
| 449 | 2 | public function setBacklinks(array $backlinks) : MediaInterface |
|
| 455 | |||
| 456 | /** |
||
| 457 | * @return array |
||
| 458 | */ |
||
| 459 | 2 | public function getCredits() : array |
|
| 463 | |||
| 464 | /** |
||
| 465 | * @param array $credits |
||
| 466 | * @return MediaInterface |
||
| 467 | */ |
||
| 468 | 2 | public function setCredits(array $credits) : MediaInterface |
|
| 474 | |||
| 475 | /** |
||
| 476 | * @return array |
||
| 477 | */ |
||
| 478 | 2 | public function getTexts() : array |
|
| 482 | |||
| 483 | /** |
||
| 484 | * @param array $texts |
||
| 485 | * @return MediaInterface |
||
| 486 | */ |
||
| 487 | 2 | public function setTexts(array $texts) : MediaInterface |
|
| 493 | |||
| 494 | /** |
||
| 495 | * @return array |
||
| 496 | */ |
||
| 497 | 2 | public function getPrices() : array |
|
| 501 | |||
| 502 | /** |
||
| 503 | * @param array $prices |
||
| 504 | * @return MediaInterface |
||
| 505 | */ |
||
| 506 | 2 | public function setPrices(array $prices) : MediaInterface |
|
| 512 | |||
| 513 | /** |
||
| 514 | * @return array |
||
| 515 | */ |
||
| 516 | 1 | public function getSubTitles() : array |
|
| 520 | |||
| 521 | /** |
||
| 522 | * @param array $subTitles |
||
| 523 | * @return MediaInterface |
||
| 524 | */ |
||
| 525 | 1 | public function setSubTitles(array $subTitles) : MediaInterface |
|
| 531 | |||
| 532 | /** |
||
| 533 | * @return array |
||
| 534 | */ |
||
| 535 | 1 | public function getScenes() : array |
|
| 539 | |||
| 540 | /** |
||
| 541 | * @param array $scenes |
||
| 542 | * @return MediaInterface |
||
| 543 | */ |
||
| 544 | 1 | public function setScenes(array $scenes) : MediaInterface |
|
| 550 | |||
| 551 | /** |
||
| 552 | * @return MediaContentInterface |
||
| 553 | */ |
||
| 554 | 2 | public function getContent() : MediaContentInterface |
|
| 558 | |||
| 559 | /** |
||
| 560 | * @param MediaContentInterface $content |
||
| 561 | * @return MediaInterface |
||
| 562 | */ |
||
| 563 | 47 | public function setContent(MediaContentInterface $content) : MediaInterface |
|
| 569 | |||
| 570 | /** |
||
| 571 | * @return MediaThumbnailInterface |
||
| 572 | */ |
||
| 573 | 3 | public function getThumbnail() : MediaThumbnailInterface |
|
| 577 | |||
| 578 | /** |
||
| 579 | * @param MediaThumbnailInterface $thumbnail |
||
| 580 | * @return MediaInterface |
||
| 581 | */ |
||
| 582 | 3 | public function setThumbnail(MediaThumbnailInterface $thumbnail) : MediaInterface |
|
| 588 | |||
| 589 | /** |
||
| 590 | * @return array |
||
| 591 | */ |
||
| 592 | 1 | public function toArray() : array |
|
| 596 | |||
| 597 | /** |
||
| 598 | * @return MediaCategoryInterface |
||
| 599 | */ |
||
| 600 | 2 | public function getCategory() : MediaCategoryInterface |
|
| 604 | |||
| 605 | /** |
||
| 606 | * @param MediaCategoryInterface $category |
||
| 607 | * @return MediaInterface |
||
| 608 | */ |
||
| 609 | 2 | public function setCategory(MediaCategoryInterface $category) : MediaInterface |
|
| 615 | |||
| 616 | /** |
||
| 617 | * @return MediaPlayerInterface |
||
| 618 | */ |
||
| 619 | 2 | public function getPlayer() : MediaPlayerInterface |
|
| 623 | |||
| 624 | /** |
||
| 625 | * @param MediaPlayerInterface $player |
||
| 626 | * @return MediaInterface |
||
| 627 | */ |
||
| 628 | 2 | public function setPlayer(MediaPlayerInterface $player) : MediaInterface |
|
| 634 | |||
| 635 | /** |
||
| 636 | * @return MediaHashInterface |
||
| 637 | */ |
||
| 638 | 2 | public function getHash() : MediaHashInterface |
|
| 642 | |||
| 643 | /** |
||
| 644 | * @param MediaHashInterface $hash |
||
| 645 | * @return MediaInterface |
||
| 646 | */ |
||
| 647 | 2 | public function setHash(MediaHashInterface $hash) : MediaInterface |
|
| 653 | |||
| 654 | /** |
||
| 655 | * @return MediaEmbedInterface |
||
| 656 | */ |
||
| 657 | 2 | public function getEmbed() : MediaEmbedInterface |
|
| 661 | |||
| 662 | /** |
||
| 663 | * @param MediaEmbedInterface $embed |
||
| 664 | * @return MediaInterface |
||
| 665 | */ |
||
| 666 | 2 | public function setEmbed(MediaEmbedInterface $embed) : MediaInterface |
|
| 672 | |||
| 673 | /** |
||
| 674 | * @return MediaLicenseInterface |
||
| 675 | */ |
||
| 676 | 1 | public function getLicense() : MediaLicenseInterface |
|
| 680 | |||
| 681 | /** |
||
| 682 | * @param MediaLicenseInterface $license |
||
| 683 | * @return MediaInterface |
||
| 684 | */ |
||
| 685 | 1 | public function setLicense(MediaLicenseInterface $license) : MediaInterface |
|
| 691 | |||
| 692 | /** |
||
| 693 | * @return MediaCommunityInterface |
||
| 694 | */ |
||
| 695 | 2 | public function getCommunity() : MediaCommunityInterface |
|
| 699 | |||
| 700 | /** |
||
| 701 | * @param MediaCommunityInterface $community |
||
| 702 | * @return MediaInterface |
||
| 703 | */ |
||
| 704 | 3 | public function setCommunity(MediaCommunityInterface $community) : MediaInterface |
|
| 710 | |||
| 711 | /** |
||
| 712 | * @return MediaRestrictionInterface |
||
| 713 | */ |
||
| 714 | 2 | public function getRestriction() : MediaRestrictionInterface |
|
| 718 | |||
| 719 | /** |
||
| 720 | * @param MediaRestrictionInterface $restriction |
||
| 721 | * @return MediaInterface |
||
| 722 | */ |
||
| 723 | 2 | public function setRestriction(MediaRestrictionInterface $restriction) : MediaInterface |
|
| 729 | |||
| 730 | /** |
||
| 731 | * @return MediaRatingInterface |
||
| 732 | */ |
||
| 733 | 2 | public function getRating() : MediaRatingInterface |
|
| 737 | |||
| 738 | /** |
||
| 739 | * @param MediaRatingInterface $rating |
||
| 740 | * @return MediaInterface |
||
| 741 | */ |
||
| 742 | 2 | public function setRating(MediaRatingInterface $rating) : MediaInterface |
|
| 748 | |||
| 749 | /** |
||
| 750 | * @return MediaCopyrightInterface |
||
| 751 | */ |
||
| 752 | 2 | public function getCopyright() : MediaCopyrightInterface |
|
| 756 | |||
| 757 | /** |
||
| 758 | * @param MediaCopyrightInterface $copyright |
||
| 759 | * @return MediaInterface |
||
| 760 | */ |
||
| 761 | 2 | public function setCopyright(MediaCopyrightInterface $copyright) : MediaInterface |
|
| 767 | |||
| 768 | /** |
||
| 769 | * @return MediaStatusInterface |
||
| 770 | */ |
||
| 771 | 2 | public function getStatus() : MediaStatusInterface |
|
| 775 | |||
| 776 | /** |
||
| 777 | * @param MediaStatusInterface $status |
||
| 778 | * @return MediaInterface |
||
| 779 | */ |
||
| 780 | 2 | public function setStatus(MediaStatusInterface $status) : MediaInterface |
|
| 786 | |||
| 787 | /** |
||
| 788 | * @return MediaPeerLinkInterface |
||
| 789 | */ |
||
| 790 | 1 | public function getPeerLink() : MediaPeerLinkInterface |
|
| 794 | |||
| 795 | /** |
||
| 796 | * @param MediaPeerLinkInterface $peerLink |
||
| 797 | * @return MediaInterface |
||
| 798 | */ |
||
| 799 | 1 | public function setPeerLink(MediaPeerLinkInterface $peerLink) : MediaInterface |
|
| 805 | } |
||
| 806 |