Complex classes like Image 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 Image, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class Image implements ImageInterface |
||
| 10 | { |
||
| 11 | |||
| 12 | //TODO: implement functions to get links to images in different sizes |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $imageId; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $title; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $description; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var \DateTime |
||
| 31 | */ |
||
| 32 | protected $uploadedAt; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $type; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var bool |
||
| 41 | */ |
||
| 42 | protected $animated; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var int |
||
| 46 | */ |
||
| 47 | protected $width; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var int |
||
| 51 | */ |
||
| 52 | protected $height; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var int |
||
| 56 | */ |
||
| 57 | protected $size; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var int |
||
| 61 | */ |
||
| 62 | protected $views; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var int |
||
| 66 | */ |
||
| 67 | protected $bandwith; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | protected $deleteHash; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string |
||
| 76 | */ |
||
| 77 | protected $name; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | protected $section; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | protected $link; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | protected $gifv; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | protected $mp4; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | protected $webm; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var bool |
||
| 106 | */ |
||
| 107 | protected $looping; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var bool |
||
| 111 | */ |
||
| 112 | protected $favorite; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var bool |
||
| 116 | */ |
||
| 117 | protected $nsfw; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var string |
||
| 121 | */ |
||
| 122 | protected $vote; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param string $imageId |
||
| 126 | * @return ImageInterface |
||
| 127 | */ |
||
| 128 | 1 | public function setImageId($imageId) |
|
| 134 | |||
| 135 | /** |
||
| 136 | * @return string |
||
| 137 | */ |
||
| 138 | 1 | public function getImageId() |
|
| 142 | |||
| 143 | /** |
||
| 144 | * @param string $title |
||
| 145 | * @return ImageInterface |
||
| 146 | */ |
||
| 147 | 1 | public function setTitle($title) |
|
| 153 | |||
| 154 | /** |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | 1 | public function getTitle() |
|
| 161 | |||
| 162 | /** |
||
| 163 | * @param string $description |
||
| 164 | * @return ImageInterface |
||
| 165 | */ |
||
| 166 | 1 | public function setDescription($description) |
|
| 172 | |||
| 173 | /** |
||
| 174 | * @return string |
||
| 175 | */ |
||
| 176 | 1 | public function getDescription() |
|
| 180 | |||
| 181 | /** |
||
| 182 | * @param \DateTime $uploadedAt |
||
| 183 | * @return ImageInterface |
||
| 184 | */ |
||
| 185 | 1 | public function setUploadedAt($uploadedAt) |
|
| 191 | |||
| 192 | /** |
||
| 193 | * @return \DateTime |
||
| 194 | */ |
||
| 195 | 1 | public function getUploadedAt() |
|
| 199 | |||
| 200 | /** |
||
| 201 | * @param string $type |
||
| 202 | * @return ImageInterface |
||
| 203 | */ |
||
| 204 | 1 | public function setType($type) |
|
| 210 | |||
| 211 | /** |
||
| 212 | * @return string |
||
| 213 | */ |
||
| 214 | 1 | public function getType() |
|
| 218 | |||
| 219 | /** |
||
| 220 | * @param bool $animated |
||
| 221 | * @return ImageInterface |
||
| 222 | */ |
||
| 223 | 1 | public function setAnimated($animated) |
|
| 229 | |||
| 230 | /** |
||
| 231 | * @return bool |
||
| 232 | */ |
||
| 233 | 1 | public function isAnimated() |
|
| 237 | |||
| 238 | /** |
||
| 239 | * @param int $width |
||
| 240 | * @return ImageInterface |
||
| 241 | */ |
||
| 242 | 1 | public function setWidth($width) |
|
| 248 | |||
| 249 | /** |
||
| 250 | * @return int |
||
| 251 | */ |
||
| 252 | 1 | public function getWidth() |
|
| 256 | |||
| 257 | /** |
||
| 258 | * @param int $height |
||
| 259 | * @return ImageInterface |
||
| 260 | */ |
||
| 261 | 1 | public function setHeight($height) |
|
| 267 | |||
| 268 | /** |
||
| 269 | * @return int |
||
| 270 | */ |
||
| 271 | 1 | public function getHeight() |
|
| 275 | |||
| 276 | /** |
||
| 277 | * @param int $size |
||
| 278 | * @return ImageInterface |
||
| 279 | */ |
||
| 280 | 1 | public function setSize($size) |
|
| 286 | |||
| 287 | /** |
||
| 288 | * @return int |
||
| 289 | */ |
||
| 290 | 1 | public function getSize() |
|
| 294 | |||
| 295 | /** |
||
| 296 | * @param int $views |
||
| 297 | * @return ImageInterface |
||
| 298 | */ |
||
| 299 | 1 | public function setViews($views) |
|
| 305 | |||
| 306 | /** |
||
| 307 | * @return int |
||
| 308 | */ |
||
| 309 | 1 | public function getViews() |
|
| 313 | |||
| 314 | /** |
||
| 315 | * @param int $bandwith |
||
| 316 | * @return ImageInterface |
||
| 317 | */ |
||
| 318 | 1 | public function setBandwith($bandwith) |
|
| 324 | |||
| 325 | /** |
||
| 326 | * @return int |
||
| 327 | */ |
||
| 328 | 1 | public function getBandwith() |
|
| 332 | |||
| 333 | /** |
||
| 334 | * @param string $deleteHash |
||
| 335 | * @return ImageInterface |
||
| 336 | */ |
||
| 337 | 1 | public function setDeleteHash($deleteHash) |
|
| 343 | |||
| 344 | /** |
||
| 345 | * @return string |
||
| 346 | */ |
||
| 347 | 1 | public function getDeleteHash() |
|
| 351 | |||
| 352 | /** |
||
| 353 | * @param string $name |
||
| 354 | * @return ImageInterface |
||
| 355 | */ |
||
| 356 | 1 | public function setName($name) |
|
| 362 | |||
| 363 | /** |
||
| 364 | * @return string |
||
| 365 | */ |
||
| 366 | 1 | public function getName() |
|
| 370 | |||
| 371 | /** |
||
| 372 | * @param string $section |
||
| 373 | * @return ImageInterface |
||
| 374 | */ |
||
| 375 | 1 | public function setSection($section) |
|
| 381 | |||
| 382 | /** |
||
| 383 | * @return string |
||
| 384 | */ |
||
| 385 | 1 | public function getSection() |
|
| 389 | |||
| 390 | /** |
||
| 391 | * @param string $link |
||
| 392 | * @return ImageInterface |
||
| 393 | */ |
||
| 394 | 1 | public function setLink($link) |
|
| 400 | |||
| 401 | /** |
||
| 402 | * @return string |
||
| 403 | */ |
||
| 404 | 1 | public function getLink() |
|
| 408 | |||
| 409 | /** |
||
| 410 | * @param string $gifv |
||
| 411 | * @return ImageInterface |
||
| 412 | */ |
||
| 413 | 1 | public function setGifv($gifv) |
|
| 419 | |||
| 420 | /** |
||
| 421 | * @return string |
||
| 422 | */ |
||
| 423 | 1 | public function getGifv() |
|
| 427 | |||
| 428 | /** |
||
| 429 | * @param string $mp4 |
||
| 430 | * @return ImageInterface |
||
| 431 | */ |
||
| 432 | 1 | public function setMp4($mp4) |
|
| 438 | |||
| 439 | /** |
||
| 440 | * @return string |
||
| 441 | */ |
||
| 442 | 1 | public function getMp4() |
|
| 446 | |||
| 447 | /** |
||
| 448 | * @param string $webm |
||
| 449 | * @return ImageInterface |
||
| 450 | */ |
||
| 451 | 1 | public function setWebm($webm) |
|
| 457 | |||
| 458 | /** |
||
| 459 | * @return string |
||
| 460 | */ |
||
| 461 | 1 | public function getWebm() |
|
| 465 | |||
| 466 | /** |
||
| 467 | * @param bool $looping |
||
| 468 | * @return ImageInterface |
||
| 469 | */ |
||
| 470 | 1 | public function setLooping($looping) |
|
| 476 | |||
| 477 | /** |
||
| 478 | * @return bool |
||
| 479 | */ |
||
| 480 | 1 | public function isLooping() |
|
| 484 | |||
| 485 | /** |
||
| 486 | * @param bool $favorite |
||
| 487 | * @return ImageInterface |
||
| 488 | */ |
||
| 489 | 1 | public function setFavorite($favorite) |
|
| 495 | |||
| 496 | /** |
||
| 497 | * @return bool |
||
| 498 | */ |
||
| 499 | 1 | public function isFavorite() |
|
| 503 | |||
| 504 | /** |
||
| 505 | * @param bool $nsfw |
||
| 506 | * @return ImageInterface |
||
| 507 | */ |
||
| 508 | 1 | public function setNsfw($nsfw) |
|
| 514 | |||
| 515 | /** |
||
| 516 | * @return bool |
||
| 517 | */ |
||
| 518 | 1 | public function isNsfw() |
|
| 522 | |||
| 523 | /** |
||
| 524 | * @param string $vote |
||
| 525 | * @return ImageInterface |
||
| 526 | */ |
||
| 527 | 1 | public function setVote($vote) |
|
| 533 | |||
| 534 | /** |
||
| 535 | * @return string |
||
| 536 | */ |
||
| 537 | 1 | public function getVote() |
|
| 541 | } |