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 | ||
| 17 | abstract class Media implements MediaInterface | ||
| 18 | { | ||
| 19 | /** | ||
| 20 | * @var string | ||
| 21 | */ | ||
| 22 | protected $name; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * @var string | ||
| 26 | */ | ||
| 27 | protected $description; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * @var bool | ||
| 31 | */ | ||
| 32 | protected $enabled = false; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * @var string | ||
| 36 | */ | ||
| 37 | protected $providerName; | ||
| 38 | |||
| 39 | /** | ||
| 40 | * @var int | ||
| 41 | */ | ||
| 42 | protected $providerStatus; | ||
| 43 | |||
| 44 | /** | ||
| 45 | * @var string | ||
| 46 | */ | ||
| 47 | protected $providerReference; | ||
| 48 | |||
| 49 | /** | ||
| 50 | * @var array | ||
| 51 | */ | ||
| 52 | protected $providerMetadata = array(); | ||
| 53 | |||
| 54 | /** | ||
| 55 | * @var int | ||
| 56 | */ | ||
| 57 | protected $width; | ||
| 58 | |||
| 59 | /** | ||
| 60 | * @var int | ||
| 61 | */ | ||
| 62 | protected $height; | ||
| 63 | |||
| 64 | /** | ||
| 65 | * @var float | ||
| 66 | */ | ||
| 67 | protected $length; | ||
| 68 | |||
| 69 | /** | ||
| 70 | * @var string | ||
| 71 | */ | ||
| 72 | protected $copyright; | ||
| 73 | |||
| 74 | /** | ||
| 75 | * @var string | ||
| 76 | */ | ||
| 77 | protected $authorName; | ||
| 78 | |||
| 79 | /** | ||
| 80 | * @var string | ||
| 81 | */ | ||
| 82 | protected $context; | ||
| 83 | |||
| 84 | /** | ||
| 85 | * @var bool | ||
| 86 | */ | ||
| 87 | protected $cdnIsFlushable; | ||
| 88 | |||
| 89 | /** | ||
| 90 | * @var string | ||
| 91 | */ | ||
| 92 | protected $cdnFlushIdentifier; | ||
| 93 | |||
| 94 | /** | ||
| 95 | * @var \DateTime | ||
| 96 | */ | ||
| 97 | protected $cdnFlushAt; | ||
| 98 | |||
| 99 | /** | ||
| 100 | * @var int | ||
| 101 | */ | ||
| 102 | protected $cdnStatus; | ||
| 103 | |||
| 104 | /** | ||
| 105 | * @var \DateTime | ||
| 106 | */ | ||
| 107 | protected $updatedAt; | ||
| 108 | |||
| 109 | /** | ||
| 110 | * @var \DateTime | ||
| 111 | */ | ||
| 112 | protected $createdAt; | ||
| 113 | |||
| 114 | /** | ||
| 115 | * @var mixed | ||
| 116 | */ | ||
| 117 | protected $binaryContent; | ||
| 118 | |||
| 119 | /** | ||
| 120 | * @var string | ||
| 121 | */ | ||
| 122 | protected $previousProviderReference; | ||
| 123 | |||
| 124 | /** | ||
| 125 | * @var string | ||
| 126 | */ | ||
| 127 | protected $contentType; | ||
| 128 | |||
| 129 | /** | ||
| 130 | * @var int | ||
| 131 | */ | ||
| 132 | protected $size; | ||
| 133 | |||
| 134 | /** | ||
| 135 | * @var GalleryItemInterface[] | ||
| 136 | */ | ||
| 137 | protected $galleryItems; | ||
| 138 | |||
| 139 | /** | ||
| 140 | * @var CategoryInterface | ||
| 141 | */ | ||
| 142 | protected $category; | ||
| 143 | |||
| 144 | /** | ||
| 145 |      * {@inheritdoc} | ||
| 146 | */ | ||
| 147 | public function __toString() | ||
| 151 | |||
| 152 | public function prePersist() | ||
| 157 | |||
| 158 | public function preUpdate() | ||
| 162 | |||
| 163 | /** | ||
| 164 | * @static | ||
| 165 | * | ||
| 166 | * @return string[] | ||
| 167 | */ | ||
| 168 | public static function getStatusList() | ||
| 178 | |||
| 179 | /** | ||
| 180 |      * {@inheritdoc} | ||
| 181 | */ | ||
| 182 | public function setBinaryContent($binaryContent) | ||
| 188 | |||
| 189 | /** | ||
| 190 |      * {@inheritdoc} | ||
| 191 | */ | ||
| 192 | public function resetBinaryContent() | ||
| 196 | |||
| 197 | /** | ||
| 198 |      * {@inheritdoc} | ||
| 199 | */ | ||
| 200 | public function getBinaryContent() | ||
| 204 | |||
| 205 | /** | ||
| 206 |      * {@inheritdoc} | ||
| 207 | */ | ||
| 208 | public function getMetadataValue($name, $default = null) | ||
| 214 | |||
| 215 | /** | ||
| 216 |      * {@inheritdoc} | ||
| 217 | */ | ||
| 218 | public function setMetadataValue($name, $value) | ||
| 224 | |||
| 225 | /** | ||
| 226 |      * {@inheritdoc} | ||
| 227 | */ | ||
| 228 | public function unsetMetadataValue($name) | ||
| 234 | |||
| 235 | /** | ||
| 236 |      * {@inheritdoc} | ||
| 237 | */ | ||
| 238 | public function setName($name) | ||
| 242 | |||
| 243 | /** | ||
| 244 |      * {@inheritdoc} | ||
| 245 | */ | ||
| 246 | public function getName() | ||
| 250 | |||
| 251 | /** | ||
| 252 |      * {@inheritdoc} | ||
| 253 | */ | ||
| 254 | public function setDescription($description) | ||
| 258 | |||
| 259 | /** | ||
| 260 |      * {@inheritdoc} | ||
| 261 | */ | ||
| 262 | public function getDescription() | ||
| 266 | |||
| 267 | /** | ||
| 268 |      * {@inheritdoc} | ||
| 269 | */ | ||
| 270 | public function setEnabled($enabled) | ||
| 274 | |||
| 275 | /** | ||
| 276 |      * {@inheritdoc} | ||
| 277 | */ | ||
| 278 | public function getEnabled() | ||
| 282 | |||
| 283 | /** | ||
| 284 |      * {@inheritdoc} | ||
| 285 | */ | ||
| 286 | public function setProviderName($providerName) | ||
| 290 | |||
| 291 | /** | ||
| 292 |      * {@inheritdoc} | ||
| 293 | */ | ||
| 294 | public function getProviderName() | ||
| 298 | |||
| 299 | /** | ||
| 300 |      * {@inheritdoc} | ||
| 301 | */ | ||
| 302 | public function setProviderStatus($providerStatus) | ||
| 306 | |||
| 307 | /** | ||
| 308 |      * {@inheritdoc} | ||
| 309 | */ | ||
| 310 | public function getProviderStatus() | ||
| 314 | |||
| 315 | /** | ||
| 316 |      * {@inheritdoc} | ||
| 317 | */ | ||
| 318 | public function setProviderReference($providerReference) | ||
| 322 | |||
| 323 | /** | ||
| 324 |      * {@inheritdoc} | ||
| 325 | */ | ||
| 326 | public function getProviderReference() | ||
| 330 | |||
| 331 | /** | ||
| 332 |      * {@inheritdoc} | ||
| 333 | */ | ||
| 334 | public function setProviderMetadata(array $providerMetadata = array()) | ||
| 338 | |||
| 339 | /** | ||
| 340 |      * {@inheritdoc} | ||
| 341 | */ | ||
| 342 | public function getProviderMetadata() | ||
| 346 | |||
| 347 | /** | ||
| 348 |      * {@inheritdoc} | ||
| 349 | */ | ||
| 350 | public function setWidth($width) | ||
| 354 | |||
| 355 | /** | ||
| 356 |      * {@inheritdoc} | ||
| 357 | */ | ||
| 358 | public function getWidth() | ||
| 362 | |||
| 363 | /** | ||
| 364 |      * {@inheritdoc} | ||
| 365 | */ | ||
| 366 | public function setHeight($height) | ||
| 370 | |||
| 371 | /** | ||
| 372 |      * {@inheritdoc} | ||
| 373 | */ | ||
| 374 | public function getHeight() | ||
| 378 | |||
| 379 | /** | ||
| 380 |      * {@inheritdoc} | ||
| 381 | */ | ||
| 382 | public function setLength($length) | ||
| 386 | |||
| 387 | /** | ||
| 388 |      * {@inheritdoc} | ||
| 389 | */ | ||
| 390 | public function getLength() | ||
| 394 | |||
| 395 | /** | ||
| 396 |      * {@inheritdoc} | ||
| 397 | */ | ||
| 398 | public function setCopyright($copyright) | ||
| 402 | |||
| 403 | /** | ||
| 404 |      * {@inheritdoc} | ||
| 405 | */ | ||
| 406 | public function getCopyright() | ||
| 410 | |||
| 411 | /** | ||
| 412 |      * {@inheritdoc} | ||
| 413 | */ | ||
| 414 | public function setAuthorName($authorName) | ||
| 418 | |||
| 419 | /** | ||
| 420 |      * {@inheritdoc} | ||
| 421 | */ | ||
| 422 | public function getAuthorName() | ||
| 426 | |||
| 427 | /** | ||
| 428 |      * {@inheritdoc} | ||
| 429 | */ | ||
| 430 | public function setContext($context) | ||
| 434 | |||
| 435 | /** | ||
| 436 |      * {@inheritdoc} | ||
| 437 | */ | ||
| 438 | public function getContext() | ||
| 442 | |||
| 443 | /** | ||
| 444 |      * {@inheritdoc} | ||
| 445 | */ | ||
| 446 | public function setCdnIsFlushable($cdnIsFlushable) | ||
| 450 | |||
| 451 | /** | ||
| 452 |      * {@inheritdoc} | ||
| 453 | */ | ||
| 454 | public function getCdnIsFlushable() | ||
| 458 | |||
| 459 | /** | ||
| 460 |      * {@inheritdoc} | ||
| 461 | */ | ||
| 462 | public function setCdnFlushIdentifier($cdnFlushIdentifier) | ||
| 466 | |||
| 467 | /** | ||
| 468 |      * {@inheritdoc} | ||
| 469 | */ | ||
| 470 | public function getCdnFlushIdentifier() | ||
| 474 | |||
| 475 | /** | ||
| 476 |      * {@inheritdoc} | ||
| 477 | */ | ||
| 478 | public function setCdnFlushAt(\DateTime $cdnFlushAt = null) | ||
| 482 | |||
| 483 | /** | ||
| 484 |      * {@inheritdoc} | ||
| 485 | */ | ||
| 486 | public function getCdnFlushAt() | ||
| 490 | |||
| 491 | /** | ||
| 492 |      * {@inheritdoc} | ||
| 493 | */ | ||
| 494 | public function setUpdatedAt(\DateTime $updatedAt = null) | ||
| 498 | |||
| 499 | /** | ||
| 500 |      * {@inheritdoc} | ||
| 501 | */ | ||
| 502 | public function getUpdatedAt() | ||
| 506 | |||
| 507 | /** | ||
| 508 |      * {@inheritdoc} | ||
| 509 | */ | ||
| 510 | public function setCreatedAt(\DateTime $createdAt = null) | ||
| 514 | |||
| 515 | /** | ||
| 516 |      * {@inheritdoc} | ||
| 517 | */ | ||
| 518 | public function getCreatedAt() | ||
| 522 | |||
| 523 | /** | ||
| 524 |      * {@inheritdoc} | ||
| 525 | */ | ||
| 526 | public function setContentType($contentType) | ||
| 530 | |||
| 531 | /** | ||
| 532 |      * {@inheritdoc} | ||
| 533 | */ | ||
| 534 | public function getContentType() | ||
| 538 | |||
| 539 | /** | ||
| 540 |      * {@inheritdoc} | ||
| 541 | */ | ||
| 542 | public function getExtension() | ||
| 547 | |||
| 548 | /** | ||
| 549 |      * {@inheritdoc} | ||
| 550 | */ | ||
| 551 | public function setSize($size) | ||
| 555 | |||
| 556 | /** | ||
| 557 |      * {@inheritdoc} | ||
| 558 | */ | ||
| 559 | public function getSize() | ||
| 563 | |||
| 564 | /** | ||
| 565 |      * {@inheritdoc} | ||
| 566 | */ | ||
| 567 | public function setCdnStatus($cdnStatus) | ||
| 571 | |||
| 572 | /** | ||
| 573 |      * {@inheritdoc} | ||
| 574 | */ | ||
| 575 | public function getCdnStatus() | ||
| 579 | |||
| 580 | /** | ||
| 581 |      * {@inheritdoc} | ||
| 582 | */ | ||
| 583 | public function getBox() | ||
| 587 | |||
| 588 | /** | ||
| 589 |      * {@inheritdoc} | ||
| 590 | */ | ||
| 591 | public function setGalleryItems($galleryItems) | ||
| 595 | |||
| 596 | /** | ||
| 597 |      * {@inheritdoc} | ||
| 598 | */ | ||
| 599 | public function getGalleryItems() | ||
| 603 | |||
| 604 | /** | ||
| 605 |      * {@inheritdoc} | ||
| 606 | */ | ||
| 607 | public function getPreviousProviderReference() | ||
| 611 | |||
| 612 | /** | ||
| 613 | * @param ExecutionContextInterface $context | ||
| 614 | */ | ||
| 615 | public function isStatusErroneous(ExecutionContextInterface $context) | ||
| 623 | |||
| 624 | /** | ||
| 625 | * @return CategoryInterface | ||
| 626 | */ | ||
| 627 | public function getCategory() | ||
| 631 | |||
| 632 | /** | ||
| 633 | * @param CategoryInterface|null $category | ||
| 634 | */ | ||
| 635 | public function setCategory($category = null) | ||
| 645 | } | ||
| 646 | 
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.