Complex classes like Video 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 Video, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class Video implements OutputInterface, AppendAttributeInterface |
||
15 | { |
||
16 | /** |
||
17 | * URL pointing to an image thumbnail. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $thumbnailLoc; |
||
22 | |||
23 | /** |
||
24 | * Title of the video, max 100 characters. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $title; |
||
29 | |||
30 | /** |
||
31 | * Description of the video, max 2048 characters. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $description; |
||
36 | |||
37 | /** |
||
38 | * URL pointing to the actual media file (mp4). |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $contentLoc; |
||
43 | |||
44 | /** |
||
45 | * URL pointing to the player file (normally a SWF). |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $playerLoc; |
||
50 | |||
51 | /** |
||
52 | * Indicates whether the video is live. |
||
53 | * |
||
54 | * @var boolean |
||
55 | */ |
||
56 | protected $live; |
||
57 | |||
58 | /** |
||
59 | * Duration of the video in seconds. |
||
60 | * |
||
61 | * @var integer |
||
62 | */ |
||
63 | protected $duration; |
||
64 | |||
65 | /** |
||
66 | * String of space delimited platform values. |
||
67 | * |
||
68 | * Allowed values are web, mobile, and tv. |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $platform; |
||
73 | |||
74 | /** |
||
75 | * Does the video require a subscription? |
||
76 | * |
||
77 | * @var boolean |
||
78 | */ |
||
79 | protected $requiresSubscription; |
||
80 | |||
81 | /** |
||
82 | * The price to download or view the video in ISO 4217 format. |
||
83 | * |
||
84 | * @link http://en.wikipedia.org/wiki/ISO_4217 |
||
85 | * |
||
86 | * @var string |
||
87 | */ |
||
88 | protected $price; |
||
89 | |||
90 | /** |
||
91 | * Link to gallery of which this video appears in. |
||
92 | * |
||
93 | * @var string |
||
94 | */ |
||
95 | protected $galleryLoc; |
||
96 | |||
97 | /** |
||
98 | * A space-delimited list of countries where the video may or may not be played. |
||
99 | * |
||
100 | * @var string |
||
101 | */ |
||
102 | protected $restriction; |
||
103 | |||
104 | /** |
||
105 | * A tag associated with the video. |
||
106 | * |
||
107 | * @var array |
||
108 | */ |
||
109 | protected $tags = []; |
||
110 | |||
111 | /** |
||
112 | * The video's category. For example, cooking. |
||
113 | * |
||
114 | * @var string |
||
115 | */ |
||
116 | protected $category; |
||
117 | |||
118 | /** |
||
119 | * No if the video should be available only to users with SafeSearch turned off. |
||
120 | * |
||
121 | * @var string |
||
122 | */ |
||
123 | protected $familyFriendly; |
||
124 | |||
125 | /** |
||
126 | * The date the video was first published, in W3C format. |
||
127 | * |
||
128 | * @var string |
||
129 | */ |
||
130 | protected $publicationDate; |
||
131 | |||
132 | /** |
||
133 | * The number of times the video has been viewed. |
||
134 | * |
||
135 | * @var integer |
||
136 | */ |
||
137 | protected $viewCount; |
||
138 | |||
139 | /** |
||
140 | * The video uploader's name. Only one <video:uploader> is allowed per video. |
||
141 | * |
||
142 | * @var string |
||
143 | */ |
||
144 | protected $uploader; |
||
145 | |||
146 | /** |
||
147 | * The rating of the video. Allowed values are float numbers in the range 0.0 to 5.0. |
||
148 | * |
||
149 | * @var float |
||
150 | */ |
||
151 | protected $rating; |
||
152 | |||
153 | /** |
||
154 | * The date after which the video will no longer be available, in W3C format. |
||
155 | * |
||
156 | * @var string |
||
157 | */ |
||
158 | protected $expirationDate; |
||
159 | |||
160 | /** |
||
161 | * Video constructor. |
||
162 | * |
||
163 | * @param string $thumbnailLoc |
||
164 | * @param string $title |
||
165 | * @param string $description |
||
166 | */ |
||
167 | public function __construct($thumbnailLoc, $title, $description) |
||
173 | |||
174 | /** |
||
175 | * URL pointing to the player file (normally a SWF). |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | public function getPlayerLoc() |
||
183 | |||
184 | /** |
||
185 | * URL pointing to the player file (normally a SWF). |
||
186 | * |
||
187 | * @param string $playerLoc |
||
188 | * |
||
189 | * @return $this |
||
190 | */ |
||
191 | public function setPlayerLoc($playerLoc) |
||
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | public function generateXML(XMLWriter $XMLWriter) |
||
233 | |||
234 | /** |
||
235 | * URL pointing to an image thumbnail. |
||
236 | * |
||
237 | * @return string |
||
238 | */ |
||
239 | public function getThumbnailLoc() |
||
243 | |||
244 | /** |
||
245 | * Title of the video, max 100 characters. |
||
246 | * |
||
247 | * @return string |
||
248 | */ |
||
249 | public function getTitle() |
||
253 | |||
254 | /** |
||
255 | * Description of the video, max 2048 characters. |
||
256 | * |
||
257 | * @return string |
||
258 | */ |
||
259 | public function getDescription() |
||
263 | |||
264 | /** |
||
265 | * {@inheritdoc} |
||
266 | */ |
||
267 | protected function optionalWriteElement(XMLWriter $XMLWriter, $name, $value) |
||
273 | |||
274 | /** |
||
275 | * URL pointing to the actual media file (mp4). |
||
276 | * |
||
277 | * @return string |
||
278 | */ |
||
279 | public function getContentLoc() |
||
283 | |||
284 | /** |
||
285 | * URL pointing to the actual media file (mp4). |
||
286 | * |
||
287 | * @param string $contentLoc |
||
288 | * |
||
289 | * @return $this |
||
290 | */ |
||
291 | public function setContentLoc($contentLoc) |
||
297 | |||
298 | /** |
||
299 | * Duration of the video in seconds. |
||
300 | * |
||
301 | * @return integer |
||
302 | */ |
||
303 | public function getDuration() |
||
307 | |||
308 | /** |
||
309 | * Duration of the video in seconds. |
||
310 | * |
||
311 | * @param integer $duration |
||
312 | * |
||
313 | * @return $this |
||
314 | */ |
||
315 | public function setDuration($duration) |
||
321 | |||
322 | /** |
||
323 | * The date after which the video will no longer be available, in W3C format. |
||
324 | * |
||
325 | * @return string |
||
326 | */ |
||
327 | public function getExpirationDate() |
||
331 | |||
332 | /** |
||
333 | * The date after which the video will no longer be available, in W3C format. |
||
334 | * |
||
335 | * @param string $expirationDate |
||
336 | * |
||
337 | * @return $this |
||
338 | */ |
||
339 | public function setExpirationDate($expirationDate) |
||
345 | |||
346 | /** |
||
347 | * The rating of the video. Allowed values are float numbers in the range 0.0 to 5.0. |
||
348 | * |
||
349 | * @return float |
||
350 | */ |
||
351 | public function getRating() |
||
355 | |||
356 | /** |
||
357 | * The rating of the video. Allowed values are float numbers in the range 0.0 to 5.0. |
||
358 | * |
||
359 | * @param float $rating |
||
360 | * |
||
361 | * @return $this |
||
362 | */ |
||
363 | public function setRating($rating) |
||
369 | |||
370 | /** |
||
371 | * The number of times the video has been viewed. |
||
372 | * |
||
373 | * @return integer |
||
374 | */ |
||
375 | public function getViewCount() |
||
379 | |||
380 | /** |
||
381 | * The number of times the video has been viewed. |
||
382 | * |
||
383 | * @param integer $viewCount |
||
384 | * |
||
385 | * @return $this |
||
386 | */ |
||
387 | public function setViewCount($viewCount) |
||
393 | |||
394 | /** |
||
395 | * The date the video was first published, in W3C format. |
||
396 | * |
||
397 | * @return string |
||
398 | */ |
||
399 | public function getPublicationDate() |
||
403 | |||
404 | /** |
||
405 | * The date the video was first published, in W3C format. |
||
406 | * |
||
407 | * @param string $publicationDate |
||
408 | * |
||
409 | * @return $this |
||
410 | */ |
||
411 | public function setPublicationDate($publicationDate) |
||
417 | |||
418 | /** |
||
419 | * No if the video should be available only to users with SafeSearch turned off. |
||
420 | * |
||
421 | * @return string |
||
422 | */ |
||
423 | public function getFamilyFriendly() |
||
427 | |||
428 | /** |
||
429 | * No if the video should be available only to users with SafeSearch turned off. |
||
430 | * |
||
431 | * @param string $familyFriendly |
||
432 | * |
||
433 | * @return $this |
||
434 | */ |
||
435 | public function setFamilyFriendly($familyFriendly) |
||
441 | |||
442 | /** |
||
443 | * A tag associated with the video. |
||
444 | * |
||
445 | * @return array |
||
446 | */ |
||
447 | public function getTags() |
||
451 | |||
452 | /** |
||
453 | * A tag associated with the video. |
||
454 | * |
||
455 | * @param array $tags |
||
456 | * |
||
457 | * @return $this |
||
458 | */ |
||
459 | public function setTags($tags) |
||
465 | |||
466 | /** |
||
467 | * The video's category. For example, cooking. |
||
468 | * |
||
469 | * @return string |
||
470 | */ |
||
471 | public function getCategory() |
||
475 | |||
476 | /** |
||
477 | * The video's category. For example, cooking. |
||
478 | * |
||
479 | * @param string $category |
||
480 | * |
||
481 | * @return $this |
||
482 | */ |
||
483 | public function setCategory($category) |
||
489 | |||
490 | /** |
||
491 | * A space-delimited list of countries where the video may or may not be played. |
||
492 | * |
||
493 | * @return string |
||
494 | */ |
||
495 | public function getRestriction() |
||
499 | |||
500 | /** |
||
501 | * A space-delimited list of countries where the video may or may not be played. |
||
502 | * |
||
503 | * @param string $restriction |
||
504 | * |
||
505 | * @return $this |
||
506 | */ |
||
507 | public function setRestriction($restriction) |
||
513 | |||
514 | /** |
||
515 | * Link to gallery of which this video appears in. |
||
516 | * |
||
517 | * @return string |
||
518 | */ |
||
519 | public function getGalleryLoc() |
||
523 | |||
524 | /** |
||
525 | * Link to gallery of which this video appears in. |
||
526 | * |
||
527 | * @param string $galleryLoc |
||
528 | * |
||
529 | * @return $this |
||
530 | */ |
||
531 | public function setGalleryLoc($galleryLoc) |
||
537 | |||
538 | /** |
||
539 | * The price to download or view the video in ISO 4217 format. |
||
540 | * |
||
541 | * @return string |
||
542 | */ |
||
543 | public function getPrice() |
||
547 | |||
548 | /** |
||
549 | * The price to download or view the video in ISO 4217 format. |
||
550 | * |
||
551 | * @param string $price |
||
552 | * |
||
553 | * @return $this |
||
554 | */ |
||
555 | public function setPrice($price) |
||
561 | |||
562 | /** |
||
563 | * Does the video require a subscription? |
||
564 | * |
||
565 | * @return boolean |
||
566 | */ |
||
567 | public function getRequiresSubscription() |
||
571 | |||
572 | /** |
||
573 | * Does the video require a subscription? |
||
574 | * |
||
575 | * @param boolean $requiresSubscription |
||
576 | * |
||
577 | * @return $this |
||
578 | */ |
||
579 | public function setRequiresSubscription($requiresSubscription) |
||
585 | |||
586 | /** |
||
587 | * The video uploader's name. Only one <video:uploader> is allowed per video. |
||
588 | * |
||
589 | * @return string |
||
590 | */ |
||
591 | public function getUploader() |
||
595 | |||
596 | /** |
||
597 | * The video uploader's name. Only one <video:uploader> is allowed per video. |
||
598 | * |
||
599 | * @param string $uploader |
||
600 | * |
||
601 | * @return $this |
||
602 | */ |
||
603 | public function setUploader($uploader) |
||
609 | |||
610 | /** |
||
611 | * String of space delimited platform values. |
||
612 | * |
||
613 | * Allowed values are web, mobile, and tv. |
||
614 | * |
||
615 | * @return string |
||
616 | */ |
||
617 | public function getPlatform() |
||
621 | |||
622 | /** |
||
623 | * String of space delimited platform values. |
||
624 | * |
||
625 | * Allowed values are web, mobile, and tv. |
||
626 | * |
||
627 | * @param string $platform |
||
628 | * |
||
629 | * @return $this |
||
630 | */ |
||
631 | public function setPlatform($platform) |
||
637 | |||
638 | /** |
||
639 | * Indicates whether the video is live. |
||
640 | * |
||
641 | * @return boolean |
||
642 | */ |
||
643 | public function getLive() |
||
647 | |||
648 | /** |
||
649 | * Indicates whether the video is live. |
||
650 | * |
||
651 | * @param boolean $live |
||
652 | * |
||
653 | * @return $this |
||
654 | */ |
||
655 | public function setLive($live) |
||
661 | |||
662 | /** |
||
663 | * {@inheritdoc} |
||
664 | */ |
||
665 | public function appendAttributeToCollectionXML(XMLWriter $XMLWriter) |
||
669 | } |
||
670 |