Complex classes like Comic 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 Comic, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types = 1); |
||
| 9 | class Comic |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * The unique ID of the comic resource. |
||
| 13 | * |
||
| 14 | * @var int |
||
| 15 | */ |
||
| 16 | private $id; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The ID of the digital comic representation of this comic. |
||
| 20 | * Will be 0 if the comic is not available digitally. |
||
| 21 | * |
||
| 22 | * @var int |
||
| 23 | */ |
||
| 24 | private $digitalId; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The canonical title of the comic. |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $title; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The number of the issue in the series (will generally be 0 for collection formats). |
||
| 35 | * |
||
| 36 | * @var float |
||
| 37 | */ |
||
| 38 | private $issueNumber; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * If the issue is a variant (e.g. an alternate cover, second printing, or director’s cut), a text description of the variant. |
||
| 42 | * |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | private $variantDescription; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * The preferred description of the comic. |
||
| 49 | * |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | private $description; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * The date the resource was most recently modified. |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private $modified; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * The ISBN for the comic (generally only populated for collection formats). |
||
| 63 | * |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | private $isbn; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * The UPC barcode number for the comic (generally only populated for periodical formats). |
||
| 70 | * |
||
| 71 | * @var string |
||
| 72 | */ |
||
| 73 | private $upc; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * The Diamond code for the comic. |
||
| 77 | * |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | private $diamondCode; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * The EAN barcode for the comic. |
||
| 84 | * |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | private $ean; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * The ISSN barcode for the comic. |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | */ |
||
| 94 | private $issn; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * The publication format of the comic e.g. comic, hardcover, trade paperback. |
||
| 98 | * |
||
| 99 | * @var string |
||
| 100 | */ |
||
| 101 | private $format; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * The number of story pages in the comic. |
||
| 105 | * |
||
| 106 | * @var int |
||
| 107 | */ |
||
| 108 | private $pageCount; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * A set of descriptive text blurbs for the comic. |
||
| 112 | * |
||
| 113 | * @var array |
||
| 114 | */ |
||
| 115 | private $textObjects; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * The canonical URL identifier for this resource. |
||
| 119 | * |
||
| 120 | * @var string |
||
| 121 | */ |
||
| 122 | private $resourceURI; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * A set of public web site URLs for the resource. |
||
| 126 | * |
||
| 127 | * @var array |
||
| 128 | */ |
||
| 129 | private $urls; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * A summary representation of the series to which this comic belongs. |
||
| 133 | * |
||
| 134 | * @var SeriesSummary |
||
| 135 | */ |
||
| 136 | private $series; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * A list of variant issues for this comic |
||
| 140 | * (includes the "original" issue if the current issue is a variant). |
||
| 141 | * |
||
| 142 | * @var array |
||
| 143 | */ |
||
| 144 | private $variants; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * A list of collections which include this comic |
||
| 148 | * (will generally be empty if the comic's format is a collection). |
||
| 149 | * |
||
| 150 | * @var array |
||
| 151 | */ |
||
| 152 | private $collections; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * A list of issues collected in this comic |
||
| 156 | * (will generally be empty for periodical formats such as "comic" or "magazine"). |
||
| 157 | * |
||
| 158 | * @var array |
||
| 159 | */ |
||
| 160 | private $collectedIssues; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * A list of key dates for this comic. |
||
| 164 | * |
||
| 165 | * @var array |
||
| 166 | */ |
||
| 167 | private $dates; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * A list of prices for this comic. |
||
| 171 | * |
||
| 172 | * @var array |
||
| 173 | */ |
||
| 174 | private $prices; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * The representative image for this comic. |
||
| 178 | * |
||
| 179 | * @var Image |
||
| 180 | */ |
||
| 181 | private $thumbnail; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * A list of promotional images associated with this comic. |
||
| 185 | * |
||
| 186 | * @var array |
||
| 187 | */ |
||
| 188 | private $images; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * A resource list containing the creators associated with this comic. |
||
| 192 | * |
||
| 193 | * @var CreatorList |
||
| 194 | */ |
||
| 195 | private $creators; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * A resource list containing the characters which appear in this comic. |
||
| 199 | * |
||
| 200 | * @var CharacterList |
||
| 201 | */ |
||
| 202 | private $characters; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * A resource list containing the stories which appear in this comic. |
||
| 206 | * |
||
| 207 | * @var StoryList |
||
| 208 | */ |
||
| 209 | private $stories; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * A resource list containing the events in which this comic appears. |
||
| 213 | * |
||
| 214 | * @var EventList |
||
| 215 | */ |
||
| 216 | private $events; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @return int |
||
| 220 | */ |
||
| 221 | public function getId() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @param int $id |
||
| 228 | */ |
||
| 229 | public function setId(int $id) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return int |
||
| 236 | */ |
||
| 237 | public function getDigitalId() |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @param int $digitalId |
||
| 244 | */ |
||
| 245 | public function setDigitalId(int $digitalId) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @return string |
||
| 252 | */ |
||
| 253 | public function getTitle() |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @param string $title |
||
| 260 | */ |
||
| 261 | public function setTitle(string $title) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @return float |
||
| 268 | */ |
||
| 269 | public function getIssueNumber() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @param float $issueNumber |
||
| 276 | */ |
||
| 277 | public function setIssueNumber(float $issueNumber) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return string |
||
| 284 | */ |
||
| 285 | public function getVariantDescription() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @param string $variantDescription |
||
| 292 | */ |
||
| 293 | public function setVariantDescription(string $variantDescription) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @return string |
||
| 300 | */ |
||
| 301 | public function getDescription() |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @param string $description |
||
| 308 | */ |
||
| 309 | public function setDescription(string $description) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | public function getModified() |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @param string $modified |
||
| 324 | */ |
||
| 325 | public function setModified(string $modified) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public function getIsbn() |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @param string $isbn |
||
| 340 | */ |
||
| 341 | public function setIsbn(string $isbn) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @return string |
||
| 348 | */ |
||
| 349 | public function getUpc() |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @param string $upc |
||
| 356 | */ |
||
| 357 | public function setUpc(string $upc) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @return string |
||
| 364 | */ |
||
| 365 | public function getDiamondCode() |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @param string $diamondCode |
||
| 372 | */ |
||
| 373 | public function setDiamondCode(string $diamondCode) |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @return string |
||
| 380 | */ |
||
| 381 | public function getEan() |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @param string $ean |
||
| 388 | */ |
||
| 389 | public function setEan(string $ean) |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @return string |
||
| 396 | */ |
||
| 397 | public function getIssn() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @param string $issn |
||
| 404 | */ |
||
| 405 | public function setIssn(string $issn) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @return string |
||
| 412 | */ |
||
| 413 | public function getFormat() |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @param string $format |
||
| 420 | */ |
||
| 421 | public function setFormat(string $format) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @return int |
||
| 428 | */ |
||
| 429 | public function getPageCount() |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @param int $pageCount |
||
| 436 | */ |
||
| 437 | public function setPageCount(int $pageCount) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @return array |
||
| 444 | */ |
||
| 445 | public function getTextObjects() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param array $textObjects |
||
| 452 | */ |
||
| 453 | public function setTextObjects(array $textObjects) |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @return string |
||
| 460 | */ |
||
| 461 | public function getResourceURI() |
||
| 465 | |||
| 466 | /** |
||
| 467 | * @param string $resourceURI |
||
| 468 | */ |
||
| 469 | public function setResourceURI(string $resourceURI) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @return array |
||
| 476 | */ |
||
| 477 | public function getUrls() |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @param array $urls |
||
| 484 | */ |
||
| 485 | public function setUrls(array $urls) |
||
| 489 | |||
| 490 | /** |
||
| 491 | * @return SeriesSummary |
||
| 492 | */ |
||
| 493 | public function getSeries() |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @param SeriesSummary $series |
||
| 500 | */ |
||
| 501 | public function setSeries(SeriesSummary $series) |
||
| 505 | |||
| 506 | /** |
||
| 507 | * @return array |
||
| 508 | */ |
||
| 509 | public function getVariants() |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @param array $variants |
||
| 516 | */ |
||
| 517 | public function setVariants(array $variants) |
||
| 521 | |||
| 522 | /** |
||
| 523 | * @return array |
||
| 524 | */ |
||
| 525 | public function getCollections() |
||
| 529 | |||
| 530 | /** |
||
| 531 | * @param array $collections |
||
| 532 | */ |
||
| 533 | public function setCollections(array $collections) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @return array |
||
| 540 | */ |
||
| 541 | public function getCollectedIssues() |
||
| 545 | |||
| 546 | /** |
||
| 547 | * @param array $collectedIssues |
||
| 548 | */ |
||
| 549 | public function setCollectedIssues(array $collectedIssues) |
||
| 553 | |||
| 554 | /** |
||
| 555 | * @return array |
||
| 556 | */ |
||
| 557 | public function getDates() |
||
| 561 | |||
| 562 | /** |
||
| 563 | * @param array $dates |
||
| 564 | */ |
||
| 565 | public function setDates(array $dates) |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @return array |
||
| 572 | */ |
||
| 573 | public function getPrices() |
||
| 577 | |||
| 578 | /** |
||
| 579 | * @param array $prices |
||
| 580 | */ |
||
| 581 | public function setPrices(array $prices) |
||
| 585 | |||
| 586 | /** |
||
| 587 | * @return Image |
||
| 588 | */ |
||
| 589 | public function getThumbnail() |
||
| 593 | |||
| 594 | /** |
||
| 595 | * @param Image $thumbnail |
||
| 596 | */ |
||
| 597 | public function setThumbnail(Image $thumbnail) |
||
| 601 | |||
| 602 | /** |
||
| 603 | * @return array |
||
| 604 | */ |
||
| 605 | public function getImages() |
||
| 609 | |||
| 610 | /** |
||
| 611 | * @param array $images |
||
| 612 | */ |
||
| 613 | public function setImages(array $images) |
||
| 617 | |||
| 618 | /** |
||
| 619 | * @return CreatorList |
||
| 620 | */ |
||
| 621 | public function getCreators() |
||
| 625 | |||
| 626 | /** |
||
| 627 | * @param CreatorList $creators |
||
| 628 | */ |
||
| 629 | public function setCreators(CreatorList $creators) |
||
| 633 | |||
| 634 | /** |
||
| 635 | * @return CharacterList |
||
| 636 | */ |
||
| 637 | public function getCharacters() |
||
| 641 | |||
| 642 | /** |
||
| 643 | * @param CharacterList $characters |
||
| 644 | */ |
||
| 645 | public function setCharacters(CharacterList $characters) |
||
| 649 | |||
| 650 | /** |
||
| 651 | * @return StoryList |
||
| 652 | */ |
||
| 653 | public function getStories() |
||
| 657 | |||
| 658 | /** |
||
| 659 | * @param StoryList $stories |
||
| 660 | */ |
||
| 661 | public function setStories(StoryList $stories) |
||
| 665 | |||
| 666 | /** |
||
| 667 | * @return EventList |
||
| 668 | */ |
||
| 669 | public function getEvents() |
||
| 673 | |||
| 674 | /** |
||
| 675 | * @param EventList $events |
||
| 676 | */ |
||
| 677 | public function setEvents(EventList $events) |
||
| 681 | } |
||
| 682 |