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 |
||
| 20 | abstract class Media implements MediaInterface |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $name; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $description; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var bool |
||
| 34 | */ |
||
| 35 | protected $enabled = false; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $providerName; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var int |
||
| 44 | */ |
||
| 45 | protected $providerStatus; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $providerReference; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | protected $providerMetadata = []; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var int |
||
| 59 | */ |
||
| 60 | protected $width; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var int |
||
| 64 | */ |
||
| 65 | protected $height; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var float |
||
| 69 | */ |
||
| 70 | protected $length; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | protected $copyright; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | protected $authorName; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var string |
||
| 84 | */ |
||
| 85 | protected $context; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var bool |
||
| 89 | */ |
||
| 90 | protected $cdnIsFlushable; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var string |
||
| 94 | */ |
||
| 95 | protected $cdnFlushIdentifier; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var \DateTime |
||
| 99 | */ |
||
| 100 | protected $cdnFlushAt; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var int |
||
| 104 | */ |
||
| 105 | protected $cdnStatus; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var \DateTime |
||
| 109 | */ |
||
| 110 | protected $updatedAt; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @var \DateTime |
||
| 114 | */ |
||
| 115 | protected $createdAt; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @var mixed |
||
| 119 | */ |
||
| 120 | protected $binaryContent; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var string |
||
| 124 | */ |
||
| 125 | protected $previousProviderReference; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @var string |
||
| 129 | */ |
||
| 130 | protected $contentType; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var int |
||
| 134 | */ |
||
| 135 | protected $size; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var GalleryItemInterface[] |
||
| 139 | */ |
||
| 140 | protected $galleryItems; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @var CategoryInterface |
||
| 144 | */ |
||
| 145 | protected $category; |
||
| 146 | |||
| 147 | public function __toString() |
||
| 151 | |||
| 152 | public function prePersist(): void |
||
| 157 | |||
| 158 | public function preUpdate(): void |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @static |
||
| 165 | * |
||
| 166 | * @return string[] |
||
| 167 | */ |
||
| 168 | public static function getStatusList() |
||
| 178 | |||
| 179 | public function setBinaryContent($binaryContent): void |
||
| 185 | |||
| 186 | public function resetBinaryContent(): void |
||
| 190 | |||
| 191 | public function getBinaryContent() |
||
| 195 | |||
| 196 | public function getMetadataValue($name, $default = null) |
||
| 202 | |||
| 203 | public function setMetadataValue($name, $value): void |
||
| 209 | |||
| 210 | public function unsetMetadataValue($name): void |
||
| 216 | |||
| 217 | public function setName($name): void |
||
| 221 | |||
| 222 | public function getName() |
||
| 226 | |||
| 227 | public function setDescription($description): void |
||
| 231 | |||
| 232 | public function getDescription() |
||
| 236 | |||
| 237 | public function setEnabled($enabled): void |
||
| 241 | |||
| 242 | public function getEnabled() |
||
| 246 | |||
| 247 | public function setProviderName($providerName): void |
||
| 251 | |||
| 252 | public function getProviderName() |
||
| 256 | |||
| 257 | public function setProviderStatus($providerStatus): void |
||
| 261 | |||
| 262 | public function getProviderStatus() |
||
| 266 | |||
| 267 | public function setProviderReference($providerReference): void |
||
| 271 | |||
| 272 | public function getProviderReference() |
||
| 276 | |||
| 277 | public function setProviderMetadata(array $providerMetadata = []): void |
||
| 281 | |||
| 282 | public function getProviderMetadata() |
||
| 286 | |||
| 287 | public function setWidth($width): void |
||
| 291 | |||
| 292 | public function getWidth() |
||
| 296 | |||
| 297 | public function setHeight($height): void |
||
| 301 | |||
| 302 | public function getHeight() |
||
| 306 | |||
| 307 | public function setLength($length): void |
||
| 311 | |||
| 312 | public function getLength() |
||
| 316 | |||
| 317 | public function setCopyright($copyright): void |
||
| 321 | |||
| 322 | public function getCopyright() |
||
| 326 | |||
| 327 | public function setAuthorName($authorName): void |
||
| 331 | |||
| 332 | public function getAuthorName() |
||
| 336 | |||
| 337 | public function setContext($context): void |
||
| 341 | |||
| 342 | public function getContext() |
||
| 346 | |||
| 347 | public function setCdnIsFlushable($cdnIsFlushable): void |
||
| 351 | |||
| 352 | public function getCdnIsFlushable() |
||
| 356 | |||
| 357 | public function setCdnFlushIdentifier($cdnFlushIdentifier): void |
||
| 361 | |||
| 362 | public function getCdnFlushIdentifier() |
||
| 366 | |||
| 367 | public function setCdnFlushAt(?\DateTime $cdnFlushAt = null): void |
||
| 371 | |||
| 372 | public function getCdnFlushAt() |
||
| 376 | |||
| 377 | public function setUpdatedAt(?\DateTime $updatedAt = null): void |
||
| 381 | |||
| 382 | public function getUpdatedAt() |
||
| 386 | |||
| 387 | public function setCreatedAt(?\DateTime $createdAt = null): void |
||
| 391 | |||
| 392 | public function getCreatedAt() |
||
| 396 | |||
| 397 | public function setContentType($contentType): void |
||
| 401 | |||
| 402 | public function getContentType() |
||
| 406 | |||
| 407 | public function getExtension() |
||
| 417 | |||
| 418 | public function setSize($size): void |
||
| 422 | |||
| 423 | public function getSize() |
||
| 427 | |||
| 428 | public function setCdnStatus($cdnStatus): void |
||
| 432 | |||
| 433 | public function getCdnStatus() |
||
| 437 | |||
| 438 | public function getBox() |
||
| 442 | |||
| 443 | public function setGalleryItems($galleryItems): void |
||
| 447 | |||
| 448 | public function getGalleryItems() |
||
| 452 | |||
| 453 | public function getPreviousProviderReference() |
||
| 457 | |||
| 458 | /** |
||
| 459 | * NEXT_MAJOR: Remove this method when bumping Symfony requirement to 2.8+. |
||
| 460 | */ |
||
| 461 | public function isStatusErroneous(ExecutionContextInterface $context): void |
||
| 467 | |||
| 468 | /** |
||
| 469 | * @return CategoryInterface |
||
| 470 | */ |
||
| 471 | public function getCategory() |
||
| 475 | |||
| 476 | /** |
||
| 477 | * @param CategoryInterface|null $category |
||
| 478 | */ |
||
| 479 | public function setCategory($category = null): void |
||
| 489 | } |
||
| 490 |