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); |
||
49 | class Media implements MediaInterface |
||
50 | { |
||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $nodeName; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $type; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $url; |
||
65 | |||
66 | /** |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $length; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $title; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $description; |
||
80 | |||
81 | /** |
||
82 | * @var int |
||
83 | */ |
||
84 | protected $rights; |
||
85 | |||
86 | /** |
||
87 | * @var int |
||
88 | */ |
||
89 | protected $titleType; |
||
90 | |||
91 | /** |
||
92 | * @var int |
||
93 | */ |
||
94 | protected $descriptionType; |
||
95 | |||
96 | /** |
||
97 | * @var array |
||
98 | */ |
||
99 | protected $keywords = array(); |
||
100 | |||
101 | /** |
||
102 | * @var array |
||
103 | */ |
||
104 | protected $comments = array(); |
||
105 | |||
106 | /** |
||
107 | * @var array |
||
108 | */ |
||
109 | protected $responses = array(); |
||
110 | |||
111 | /** |
||
112 | * @var array |
||
113 | */ |
||
114 | protected $backlinks = array(); |
||
115 | |||
116 | /** |
||
117 | * @var array |
||
118 | */ |
||
119 | protected $credits = array(); |
||
120 | |||
121 | /** |
||
122 | * @var array |
||
123 | */ |
||
124 | protected $texts = array(); |
||
125 | |||
126 | /** |
||
127 | * @var array |
||
128 | */ |
||
129 | protected $prices = array(); |
||
130 | |||
131 | /** |
||
132 | * @var array |
||
133 | */ |
||
134 | protected $subTitles = array(); |
||
135 | |||
136 | /** |
||
137 | * @var array |
||
138 | */ |
||
139 | protected $scenes = array(); |
||
140 | |||
141 | /** |
||
142 | * @var MediaContentInterface |
||
143 | */ |
||
144 | protected $content; |
||
145 | |||
146 | /** |
||
147 | * @var MediaThumbnailInterface |
||
148 | */ |
||
149 | protected $thumbnail; |
||
150 | |||
151 | /** |
||
152 | * @var MediaCategoryInterface |
||
153 | */ |
||
154 | protected $category; |
||
155 | |||
156 | /** |
||
157 | * @var MediaHashInterface |
||
158 | */ |
||
159 | protected $hash; |
||
160 | |||
161 | /** |
||
162 | * @var MediaEmbedInterface |
||
163 | */ |
||
164 | protected $embed; |
||
165 | |||
166 | /** |
||
167 | * @var MediaLicenseInterface |
||
168 | */ |
||
169 | protected $license; |
||
170 | |||
171 | /** |
||
172 | * @var MediaCommunityInterface |
||
173 | */ |
||
174 | protected $community; |
||
175 | |||
176 | /** |
||
177 | * @var MediaRestrictionInterface |
||
178 | */ |
||
179 | protected $restriction; |
||
180 | |||
181 | /** |
||
182 | * @var MediaRatingInterface |
||
183 | */ |
||
184 | protected $rating; |
||
185 | |||
186 | /** |
||
187 | * @var MediaCopyrightInterface |
||
188 | */ |
||
189 | protected $copyright; |
||
190 | |||
191 | /** |
||
192 | * @var MediaPlayerInterface |
||
193 | */ |
||
194 | protected $player; |
||
195 | |||
196 | /** |
||
197 | * @var MediaStatusInterface |
||
198 | */ |
||
199 | protected $status; |
||
200 | |||
201 | /** |
||
202 | * @var MediaPeerLinkInterface |
||
203 | */ |
||
204 | protected $peerLink; |
||
205 | |||
206 | /** |
||
207 | * @return string |
||
208 | */ |
||
209 | public function getNodeName() : string |
||
213 | |||
214 | /** |
||
215 | * @param string $nodeName |
||
216 | * @return MediaInterface |
||
217 | */ |
||
218 | 51 | public function setNodeName(string $nodeName) : MediaInterface |
|
224 | |||
225 | /** |
||
226 | * @return string |
||
227 | */ |
||
228 | 7 | public function getType() : ? string |
|
232 | |||
233 | /** |
||
234 | * @param string $type |
||
235 | * @return MediaInterface |
||
236 | */ |
||
237 | 54 | public function setType(?string $type) : MediaInterface |
|
243 | |||
244 | /** |
||
245 | * @return string |
||
246 | */ |
||
247 | 10 | public function getUrl() : ? string |
|
251 | |||
252 | /** |
||
253 | * @param string $url |
||
254 | * @return MediaInterface |
||
255 | */ |
||
256 | 53 | public function setUrl(?string $url) : MediaInterface |
|
262 | |||
263 | /** |
||
264 | * @return string |
||
265 | */ |
||
266 | 3 | public function getLength() : ? string |
|
270 | |||
271 | /** |
||
272 | * @param string $length |
||
273 | * @return MediaInterface |
||
274 | */ |
||
275 | 6 | public function setLength(?string $length) : MediaInterface |
|
281 | |||
282 | /** |
||
283 | * @return string |
||
284 | */ |
||
285 | 4 | public function getTitle() : ? string |
|
289 | |||
290 | /** |
||
291 | * @param string $title |
||
292 | * @return MediaInterface |
||
293 | */ |
||
294 | 4 | public function setTitle(?string $title) : MediaInterface |
|
300 | |||
301 | /** |
||
302 | * @return string |
||
303 | */ |
||
304 | 5 | public function getDescription() : ? string |
|
308 | |||
309 | /** |
||
310 | * @param string $description |
||
311 | * @return MediaInterface |
||
312 | */ |
||
313 | 5 | public function setDescription(?string $description) : MediaInterface |
|
319 | |||
320 | /** |
||
321 | * @return string |
||
322 | */ |
||
323 | 1 | public function getRights() : ?int |
|
327 | |||
328 | /** |
||
329 | * @param int $rights |
||
330 | * @return MediaInterface |
||
331 | */ |
||
332 | 1 | public function setRights(int $rights) : MediaInterface |
|
338 | |||
339 | /** |
||
340 | * @return int |
||
341 | */ |
||
342 | 2 | public function getTitleType() : ?int |
|
346 | |||
347 | /** |
||
348 | * @param int $titleType |
||
349 | * @return MediaInterface |
||
350 | */ |
||
351 | 4 | public function setTitleType(?int $titleType) : MediaInterface |
|
357 | |||
358 | |||
359 | /** |
||
360 | * @return int |
||
361 | */ |
||
362 | 2 | public function getDescriptionType() : ?int |
|
366 | |||
367 | /** |
||
368 | * @param int $descriptionType |
||
369 | * @return MediaInterface |
||
370 | */ |
||
371 | 5 | public function setDescriptionType(?int $descriptionType) : MediaInterface |
|
377 | |||
378 | /** |
||
379 | * @return array |
||
380 | */ |
||
381 | 1 | public function getKeywords() : array |
|
385 | |||
386 | /** |
||
387 | * @param array $keywords |
||
388 | * @return MediaInterface |
||
389 | */ |
||
390 | 1 | public function setKeywords(array $keywords) : MediaInterface |
|
396 | |||
397 | /** |
||
398 | * @return array |
||
399 | */ |
||
400 | 2 | public function getComments() : array |
|
404 | |||
405 | /** |
||
406 | * @param array $comments |
||
407 | * @return MediaInterface |
||
408 | */ |
||
409 | 2 | public function setComments(array $comments) : MediaInterface |
|
415 | |||
416 | /** |
||
417 | * @return array |
||
418 | */ |
||
419 | 2 | public function getResponses() : array |
|
423 | |||
424 | /** |
||
425 | * @param array $responses |
||
426 | * @return MediaInterface |
||
427 | */ |
||
428 | 2 | public function setResponses(array $responses) : MediaInterface |
|
434 | |||
435 | /** |
||
436 | * @return array |
||
437 | */ |
||
438 | 2 | public function getBacklinks() : array |
|
442 | |||
443 | /** |
||
444 | * @param array $backlinks |
||
445 | * @return MediaInterface |
||
446 | */ |
||
447 | 2 | public function setBacklinks(array $backlinks) : MediaInterface |
|
453 | |||
454 | /** |
||
455 | * @return array |
||
456 | */ |
||
457 | 2 | public function getCredits() : array |
|
461 | |||
462 | /** |
||
463 | * @param array $credits |
||
464 | * @return MediaInterface |
||
465 | */ |
||
466 | 2 | public function setCredits(array $credits) : MediaInterface |
|
472 | |||
473 | /** |
||
474 | * @return array |
||
475 | */ |
||
476 | 2 | public function getTexts() : array |
|
480 | |||
481 | /** |
||
482 | * @param array $texts |
||
483 | * @return MediaInterface |
||
484 | */ |
||
485 | 2 | public function setTexts(array $texts) : MediaInterface |
|
491 | |||
492 | /** |
||
493 | * @return array |
||
494 | */ |
||
495 | 2 | public function getPrices() : array |
|
499 | |||
500 | /** |
||
501 | * @param array $prices |
||
502 | * @return MediaInterface |
||
503 | */ |
||
504 | 2 | public function setPrices(array $prices) : MediaInterface |
|
510 | |||
511 | /** |
||
512 | * @return array |
||
513 | */ |
||
514 | 1 | public function getSubTitles() : array |
|
518 | |||
519 | /** |
||
520 | * @param array $subTitles |
||
521 | * @return MediaInterface |
||
522 | */ |
||
523 | 1 | public function setSubTitles(array $subTitles) : MediaInterface |
|
529 | |||
530 | /** |
||
531 | * @return array |
||
532 | */ |
||
533 | 1 | public function getScenes() : array |
|
537 | |||
538 | /** |
||
539 | * @param array $scenes |
||
540 | * @return MediaInterface |
||
541 | */ |
||
542 | 1 | public function setScenes(array $scenes) : MediaInterface |
|
548 | |||
549 | /** |
||
550 | * @return MediaContentInterface |
||
551 | */ |
||
552 | 2 | public function getContent() : MediaContentInterface |
|
556 | |||
557 | /** |
||
558 | * @param MediaContentInterface $content |
||
559 | * @return MediaInterface |
||
560 | */ |
||
561 | 47 | public function setContent(MediaContentInterface $content) : MediaInterface |
|
567 | |||
568 | /** |
||
569 | * @return MediaThumbnailInterface |
||
570 | */ |
||
571 | 3 | public function getThumbnail() : MediaThumbnailInterface |
|
575 | |||
576 | /** |
||
577 | * @param MediaThumbnailInterface $thumbnail |
||
578 | * @return MediaInterface |
||
579 | */ |
||
580 | 3 | public function setThumbnail(MediaThumbnailInterface $thumbnail) : MediaInterface |
|
586 | |||
587 | /** |
||
588 | * @return MediaCategoryInterface |
||
589 | */ |
||
590 | 2 | public function getCategory() : MediaCategoryInterface |
|
594 | |||
595 | /** |
||
596 | * @param MediaCategoryInterface $category |
||
597 | * @return MediaInterface |
||
598 | */ |
||
599 | 2 | public function setCategory(MediaCategoryInterface $category) : MediaInterface |
|
605 | |||
606 | /** |
||
607 | * @return MediaPlayerInterface |
||
608 | */ |
||
609 | 2 | public function getPlayer() : MediaPlayerInterface |
|
613 | |||
614 | /** |
||
615 | * @param MediaPlayerInterface $player |
||
616 | * @return MediaInterface |
||
617 | */ |
||
618 | 2 | public function setPlayer(MediaPlayerInterface $player) : MediaInterface |
|
624 | |||
625 | /** |
||
626 | * @return MediaHashInterface |
||
627 | */ |
||
628 | 2 | public function getHash() : MediaHashInterface |
|
632 | |||
633 | /** |
||
634 | * @param MediaHashInterface $hash |
||
635 | * @return MediaInterface |
||
636 | */ |
||
637 | 2 | public function setHash(MediaHashInterface $hash) : MediaInterface |
|
643 | |||
644 | /** |
||
645 | * @return MediaEmbedInterface |
||
646 | */ |
||
647 | 2 | public function getEmbed() : MediaEmbedInterface |
|
651 | |||
652 | /** |
||
653 | * @param MediaEmbedInterface $embed |
||
654 | * @return MediaInterface |
||
655 | */ |
||
656 | 2 | public function setEmbed(MediaEmbedInterface $embed) : MediaInterface |
|
662 | |||
663 | /** |
||
664 | * @return MediaLicenseInterface |
||
665 | */ |
||
666 | 1 | public function getLicense() : MediaLicenseInterface |
|
670 | |||
671 | /** |
||
672 | * @param MediaLicenseInterface $license |
||
673 | * @return MediaInterface |
||
674 | */ |
||
675 | 1 | public function setLicense(MediaLicenseInterface $license) : MediaInterface |
|
681 | |||
682 | /** |
||
683 | * @return MediaCommunityInterface |
||
684 | */ |
||
685 | 2 | public function getCommunity() : MediaCommunityInterface |
|
689 | |||
690 | /** |
||
691 | * @param MediaCommunityInterface $community |
||
692 | * @return MediaInterface |
||
693 | */ |
||
694 | 3 | public function setCommunity(MediaCommunityInterface $community) : MediaInterface |
|
700 | |||
701 | /** |
||
702 | * @return MediaRestrictionInterface |
||
703 | */ |
||
704 | 2 | public function getRestriction() : MediaRestrictionInterface |
|
708 | |||
709 | /** |
||
710 | * @param MediaRestrictionInterface $restriction |
||
711 | * @return MediaInterface |
||
712 | */ |
||
713 | 2 | public function setRestriction(MediaRestrictionInterface $restriction) : MediaInterface |
|
719 | |||
720 | /** |
||
721 | * @return MediaRatingInterface |
||
722 | */ |
||
723 | 2 | public function getRating() : MediaRatingInterface |
|
727 | |||
728 | /** |
||
729 | * @param MediaRatingInterface $rating |
||
730 | * @return MediaInterface |
||
731 | */ |
||
732 | 2 | public function setRating(MediaRatingInterface $rating) : MediaInterface |
|
738 | |||
739 | /** |
||
740 | * @return MediaCopyrightInterface |
||
741 | */ |
||
742 | 2 | public function getCopyright() : MediaCopyrightInterface |
|
746 | |||
747 | /** |
||
748 | * @param MediaCopyrightInterface $copyright |
||
749 | * @return MediaInterface |
||
750 | */ |
||
751 | 2 | public function setCopyright(MediaCopyrightInterface $copyright) : MediaInterface |
|
757 | |||
758 | /** |
||
759 | * @return MediaStatusInterface |
||
760 | */ |
||
761 | 2 | public function getStatus() : MediaStatusInterface |
|
765 | |||
766 | /** |
||
767 | * @param MediaStatusInterface $status |
||
768 | * @return MediaInterface |
||
769 | */ |
||
770 | 2 | public function setStatus(MediaStatusInterface $status) : MediaInterface |
|
776 | |||
777 | /** |
||
778 | * @return MediaPeerLinkInterface |
||
779 | */ |
||
780 | 1 | public function getPeerLink() : MediaPeerLinkInterface |
|
784 | |||
785 | /** |
||
786 | * @param MediaPeerLinkInterface $peerLink |
||
787 | * @return MediaInterface |
||
788 | */ |
||
789 | 1 | public function setPeerLink(MediaPeerLinkInterface $peerLink) : MediaInterface |
|
795 | } |
||
796 |