Complex classes like ArticleMedia 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 ArticleMedia, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class ArticleMedia implements ArticleMediaInterface |
||
| 26 | { |
||
| 27 | use TimestampableTrait; |
||
| 28 | use SoftDeletableTrait; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var int |
||
| 32 | */ |
||
| 33 | protected $id; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | protected $key; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var FileInterface |
||
| 42 | */ |
||
| 43 | protected $file; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var ImageInterface |
||
| 47 | */ |
||
| 48 | protected $image; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var ArticleInterface |
||
| 52 | */ |
||
| 53 | protected $article; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | protected $description; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var string |
||
| 62 | */ |
||
| 63 | protected $located; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var string |
||
| 67 | */ |
||
| 68 | protected $byLine; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var string |
||
| 72 | */ |
||
| 73 | protected $body; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var string |
||
| 77 | */ |
||
| 78 | protected $mimetype; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var string |
||
| 82 | */ |
||
| 83 | protected $usageTerms; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var ArrayCollection |
||
| 87 | */ |
||
| 88 | protected $renditions; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var string|null |
||
| 92 | */ |
||
| 93 | protected $headline; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var string|null |
||
| 97 | */ |
||
| 98 | protected $copyrightHolder; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var string/null |
||
| 102 | */ |
||
| 103 | protected $copyrightNotice; |
||
| 104 | |||
| 105 | /** @var string|null */ |
||
| 106 | protected $mediaType = ArticleMediaInterface::TYPE_EMBEDDED_IMAGE; |
||
| 107 | |||
| 108 | /** @var License|null */ |
||
| 109 | protected $license; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * ArticleMedia constructor. |
||
| 113 | */ |
||
| 114 | public function __construct() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * {@inheritdoc} |
||
| 121 | */ |
||
| 122 | public function getRenditions() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * {@inheritdoc} |
||
| 129 | */ |
||
| 130 | public function addRendition(ImageRenditionInterface $rendition) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * {@inheritdoc} |
||
| 137 | */ |
||
| 138 | public function setRenditions($renditions) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * {@inheritdoc} |
||
| 145 | */ |
||
| 146 | public function getId() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * {@inheritdoc} |
||
| 153 | */ |
||
| 154 | public function getFile() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * {@inheritdoc} |
||
| 161 | */ |
||
| 162 | public function setFile($file) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * {@inheritdoc} |
||
| 171 | */ |
||
| 172 | public function getImage() |
||
| 176 | |||
| 177 | /** |
||
| 178 | * {@inheritdoc} |
||
| 179 | */ |
||
| 180 | public function setImage($image) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * {@inheritdoc} |
||
| 189 | */ |
||
| 190 | public function getArticle() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * {@inheritdoc} |
||
| 197 | */ |
||
| 198 | public function setArticle(ArticleInterface $article) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * {@inheritdoc} |
||
| 207 | */ |
||
| 208 | public function getAssetId(): ?string |
||
| 218 | |||
| 219 | /** |
||
| 220 | * {@inheritdoc} |
||
| 221 | */ |
||
| 222 | public function getDescription() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * {@inheritdoc} |
||
| 229 | */ |
||
| 230 | public function setDescription($description) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * {@inheritdoc} |
||
| 239 | */ |
||
| 240 | public function getLocated() |
||
| 244 | |||
| 245 | /** |
||
| 246 | * {@inheritdoc} |
||
| 247 | */ |
||
| 248 | public function setLocated($located) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * {@inheritdoc} |
||
| 257 | */ |
||
| 258 | public function getByLine() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * {@inheritdoc} |
||
| 265 | */ |
||
| 266 | public function setByLine($byLine) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * {@inheritdoc} |
||
| 275 | */ |
||
| 276 | public function getBody() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * {@inheritdoc} |
||
| 283 | */ |
||
| 284 | public function setBody($body) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * {@inheritdoc} |
||
| 293 | */ |
||
| 294 | public function getMimetype() |
||
| 298 | |||
| 299 | /** |
||
| 300 | * {@inheritdoc} |
||
| 301 | */ |
||
| 302 | public function setMimetype($mimetype) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * {@inheritdoc} |
||
| 311 | */ |
||
| 312 | public function getUsageTerms() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * {@inheritdoc} |
||
| 319 | */ |
||
| 320 | public function setUsageTerms($usageTerms) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * {@inheritdoc} |
||
| 329 | */ |
||
| 330 | public function getKey(): string |
||
| 334 | |||
| 335 | /** |
||
| 336 | * {@inheritdoc} |
||
| 337 | */ |
||
| 338 | public function setKey(string $key) |
||
| 342 | |||
| 343 | public function getHeadline(): ?string |
||
| 347 | |||
| 348 | public function setHeadline(?string $headline): void |
||
| 352 | |||
| 353 | public function getCopyrightNotice(): ?string |
||
| 357 | |||
| 358 | public function setCopyrightNotice(?string $copyrightNotice): void |
||
| 362 | |||
| 363 | public function getCopyrightHolder(): ?string |
||
| 367 | |||
| 368 | public function setCopyrightHolder(?string $copyrightHolder): void |
||
| 372 | |||
| 373 | public function getMediaType(): ?string |
||
| 377 | |||
| 378 | public function setMediaType(?string $mediaType): void |
||
| 382 | |||
| 383 | /** |
||
| 384 | * {@inheritdoc} |
||
| 385 | */ |
||
| 386 | public function setFromItem(ItemInterface $item) |
||
| 397 | |||
| 398 | /** |
||
| 399 | * {@inheritdoc} |
||
| 400 | */ |
||
| 401 | public static function handleMediaId($mediaId) |
||
| 411 | |||
| 412 | /** |
||
| 413 | * {@inheritdoc} |
||
| 414 | */ |
||
| 415 | public static function getOriginalMediaId(string $mediaId) |
||
| 419 | |||
| 420 | public function getLicense(): ?License |
||
| 424 | |||
| 425 | public function setLicense(License $license): void |
||
| 429 | } |
||
| 430 |