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 |
||
| 9 | class Video implements OutputInterface, AppendAttributeInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var |
||
| 13 | */ |
||
| 14 | protected $thumbnailLoc; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var |
||
| 18 | */ |
||
| 19 | protected $title; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var |
||
| 23 | */ |
||
| 24 | protected $description; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var |
||
| 28 | */ |
||
| 29 | protected $contentLoc; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var |
||
| 33 | */ |
||
| 34 | protected $playerLoc; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var |
||
| 38 | */ |
||
| 39 | protected $live; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var |
||
| 43 | */ |
||
| 44 | protected $duration; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var |
||
| 48 | */ |
||
| 49 | protected $platform; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var |
||
| 53 | */ |
||
| 54 | protected $requiresSubscription; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var |
||
| 58 | */ |
||
| 59 | protected $price; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var |
||
| 63 | */ |
||
| 64 | protected $galleryLoc; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var |
||
| 68 | */ |
||
| 69 | protected $restriction; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var array |
||
| 73 | */ |
||
| 74 | protected $tags = []; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var |
||
| 78 | */ |
||
| 79 | protected $category; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var |
||
| 83 | */ |
||
| 84 | protected $familyFriendly; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var |
||
| 88 | */ |
||
| 89 | protected $publicationDate; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var |
||
| 93 | */ |
||
| 94 | protected $viewCount; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var |
||
| 98 | */ |
||
| 99 | protected $uploader; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var |
||
| 103 | */ |
||
| 104 | protected $rating; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var |
||
| 108 | */ |
||
| 109 | protected $expirationDate; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Video constructor. |
||
| 113 | * |
||
| 114 | * @param $thumbnailLoc |
||
| 115 | * @param $title |
||
| 116 | * @param $description |
||
| 117 | */ |
||
| 118 | public function __construct($thumbnailLoc, $title, $description) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return mixed |
||
| 127 | */ |
||
| 128 | public function getPlayerLoc() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @param mixed $playerLoc |
||
| 135 | * |
||
| 136 | * @return Video |
||
| 137 | */ |
||
| 138 | public function setPlayerLoc($playerLoc) |
||
| 144 | |||
| 145 | public function generateXML(XMLWriter $XMLWriter) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @return mixed |
||
| 180 | */ |
||
| 181 | public function getThumbnailLoc() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @return mixed |
||
| 188 | */ |
||
| 189 | public function getTitle() |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @return mixed |
||
| 196 | */ |
||
| 197 | public function getDescription() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param XMLWriter $XMLWriter |
||
| 204 | * @param string $name |
||
| 205 | * @param string $value |
||
| 206 | */ |
||
| 207 | protected function optionalWriteElement(XMLWriter $XMLWriter, $name, $value) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @return mixed |
||
| 216 | */ |
||
| 217 | public function getContentLoc() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @param mixed $contentLoc |
||
| 224 | * |
||
| 225 | * @return Video |
||
| 226 | */ |
||
| 227 | public function setContentLoc($contentLoc) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return mixed |
||
| 236 | */ |
||
| 237 | public function getDuration() |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @param mixed $duration |
||
| 244 | * |
||
| 245 | * @return Video |
||
| 246 | */ |
||
| 247 | public function setDuration($duration) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @return mixed |
||
| 256 | */ |
||
| 257 | public function getExpirationDate() |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @param mixed $expirationDate |
||
| 264 | * |
||
| 265 | * @return Video |
||
| 266 | */ |
||
| 267 | public function setExpirationDate($expirationDate) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return mixed |
||
| 276 | */ |
||
| 277 | public function getRating() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @param mixed $rating |
||
| 284 | * |
||
| 285 | * @return Video |
||
| 286 | */ |
||
| 287 | public function setRating($rating) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @return mixed |
||
| 296 | */ |
||
| 297 | public function getViewCount() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @param mixed $viewCount |
||
| 304 | * |
||
| 305 | * @return Video |
||
| 306 | */ |
||
| 307 | public function setViewCount($viewCount) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @return mixed |
||
| 316 | */ |
||
| 317 | public function getPublicationDate() |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @param mixed $publicationDate |
||
| 324 | * |
||
| 325 | * @return Video |
||
| 326 | */ |
||
| 327 | public function setPublicationDate($publicationDate) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @return mixed |
||
| 336 | */ |
||
| 337 | public function getFamilyFriendly() |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @param mixed $familyFriendly |
||
| 344 | * |
||
| 345 | * @return Video |
||
| 346 | */ |
||
| 347 | public function setFamilyFriendly($familyFriendly) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return array |
||
| 356 | */ |
||
| 357 | public function getTags() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @param array $tags |
||
| 364 | * |
||
| 365 | * @return Video |
||
| 366 | */ |
||
| 367 | public function setTags($tags) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @return mixed |
||
| 376 | */ |
||
| 377 | public function getCategory() |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @param mixed $category |
||
| 384 | * |
||
| 385 | * @return Video |
||
| 386 | */ |
||
| 387 | public function setCategory($category) |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @return mixed |
||
| 396 | */ |
||
| 397 | public function getRestriction() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @param mixed $restriction |
||
| 404 | * |
||
| 405 | * @return Video |
||
| 406 | */ |
||
| 407 | public function setRestriction($restriction) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @return mixed |
||
| 416 | */ |
||
| 417 | public function getGalleryLoc() |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @param mixed $galleryLoc |
||
| 424 | * |
||
| 425 | * @return Video |
||
| 426 | */ |
||
| 427 | public function setGalleryLoc($galleryLoc) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @return mixed |
||
| 436 | */ |
||
| 437 | public function getPrice() |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @param mixed $price |
||
| 444 | * |
||
| 445 | * @return Video |
||
| 446 | */ |
||
| 447 | public function setPrice($price) |
||
| 453 | |||
| 454 | /** |
||
| 455 | * @return mixed |
||
| 456 | */ |
||
| 457 | public function getRequiresSubscription() |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @param mixed $requiresSubscription |
||
| 464 | * |
||
| 465 | * @return Video |
||
| 466 | */ |
||
| 467 | public function setRequiresSubscription($requiresSubscription) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @return mixed |
||
| 476 | */ |
||
| 477 | public function getUploader() |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @param mixed $uploader |
||
| 484 | * |
||
| 485 | * @return Video |
||
| 486 | */ |
||
| 487 | public function setUploader($uploader) |
||
| 493 | |||
| 494 | /** |
||
| 495 | * @return mixed |
||
| 496 | */ |
||
| 497 | public function getPlatform() |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @param mixed $platform |
||
| 504 | * |
||
| 505 | * @return Video |
||
| 506 | */ |
||
| 507 | public function setPlatform($platform) |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @return mixed |
||
| 516 | */ |
||
| 517 | public function getLive() |
||
| 521 | |||
| 522 | /** |
||
| 523 | * @param mixed $live |
||
| 524 | * |
||
| 525 | * @return Video |
||
| 526 | */ |
||
| 527 | public function setLive($live) |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @param XMLWriter $XMLWriter |
||
| 536 | */ |
||
| 537 | public function appendAttributeToCollectionXML(XMLWriter $XMLWriter) |
||
| 541 | } |
||
| 542 |