Complex classes like Project 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 Project, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class Project |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * URL to check for updates, if a given project doesn't define its own. |
||
| 33 | */ |
||
| 34 | const UPDATE_DEFAULT_URL = 'http://updates.drupal.org/release-history'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * |
||
| 38 | */ |
||
| 39 | const INSTALL_TYPE_OFFICIAL = 'official'; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * |
||
| 43 | */ |
||
| 44 | const INSTALL_TYPE_DEV = 'dev'; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * |
||
| 48 | */ |
||
| 49 | const INSTALL_TYPE_UNKNOWN = 'unknown'; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * |
||
| 53 | */ |
||
| 54 | const TYPE_PROJECT_DISTRIBUTION = 'project_distribution'; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * |
||
| 58 | */ |
||
| 59 | const TYPE_PROJECT_CORE = 'project_core'; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * |
||
| 63 | */ |
||
| 64 | const TYPE_PROJECT_MODULE = 'project_module'; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * |
||
| 68 | */ |
||
| 69 | const TYPE_PROJECT_THEME = 'project_theme'; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * |
||
| 73 | */ |
||
| 74 | const TYPE_UNKNOWN = 'unknown'; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var |
||
| 78 | */ |
||
| 79 | protected $project; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var string |
||
| 83 | */ |
||
| 84 | protected $filename; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var |
||
| 88 | */ |
||
| 89 | protected $name; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var |
||
| 93 | */ |
||
| 94 | protected $core; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var |
||
| 98 | */ |
||
| 99 | protected $version; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var |
||
| 103 | */ |
||
| 104 | protected $status_url; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var |
||
| 108 | */ |
||
| 109 | protected $install_type; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var |
||
| 113 | */ |
||
| 114 | protected $existing_version; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var |
||
| 118 | */ |
||
| 119 | protected $existing_major; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @var array |
||
| 123 | */ |
||
| 124 | protected $data; |
||
| 125 | |||
| 126 | // Calculated properties. |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var |
||
| 130 | */ |
||
| 131 | protected $status; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var |
||
| 135 | */ |
||
| 136 | protected $project_status; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @var string |
||
| 140 | */ |
||
| 141 | protected $project_type; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var |
||
| 145 | */ |
||
| 146 | protected $reason; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var |
||
| 150 | */ |
||
| 151 | protected $fetch_status; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var |
||
| 155 | */ |
||
| 156 | protected $latest_version; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var |
||
| 160 | */ |
||
| 161 | protected $latest_dev; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var |
||
| 165 | */ |
||
| 166 | protected $dev_version; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @var |
||
| 170 | */ |
||
| 171 | protected $recommended; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var |
||
| 175 | */ |
||
| 176 | protected $datestamp; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @var array |
||
| 180 | */ |
||
| 181 | protected $releases; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @var array |
||
| 185 | */ |
||
| 186 | protected $security_updates; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @var array |
||
| 190 | */ |
||
| 191 | protected $also_available; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param string $project |
||
| 195 | * @param string $core |
||
| 196 | * @param string $version |
||
| 197 | */ |
||
| 198 | public function __construct($project, $core, $version) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @return string |
||
| 216 | */ |
||
| 217 | public function getFilename() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @param string $filename |
||
| 224 | */ |
||
| 225 | public function setFilename($filename) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * |
||
| 234 | */ |
||
| 235 | protected function init() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param string $version |
||
| 288 | * @param Release $release |
||
| 289 | */ |
||
| 290 | public function addSecurityUpdate($version, $release) |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @param string $version |
||
| 297 | * @param Release $release |
||
| 298 | */ |
||
| 299 | public function addAlsoAvailable($version, $release) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @param string $version |
||
| 306 | * @return mixed |
||
| 307 | */ |
||
| 308 | public function getAlsoAvailable($version) |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @return mixed |
||
| 315 | */ |
||
| 316 | public function getCore() |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @return mixed |
||
| 323 | */ |
||
| 324 | public function getDatestamp() |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @return array |
||
| 331 | */ |
||
| 332 | public function getDetails() |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @return string |
||
| 339 | */ |
||
| 340 | public function getProjectType() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @param string $type |
||
| 347 | */ |
||
| 348 | public function setProjectType($type) |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @return mixed |
||
| 355 | */ |
||
| 356 | public function getDevVersion() |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @param $dev_version |
||
| 363 | */ |
||
| 364 | public function setDevVersion($dev_version) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @return string |
||
| 371 | */ |
||
| 372 | public function getExistingMajor() |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @return string |
||
| 379 | */ |
||
| 380 | public function getExistingVersion() |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @return integer |
||
| 387 | */ |
||
| 388 | public function getFetchStatus() |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @param $fetch_status |
||
| 395 | */ |
||
| 396 | public function setFetchStatus($fetch_status) |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @return string |
||
| 403 | */ |
||
| 404 | public function getInstallType() |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @return mixed |
||
| 411 | */ |
||
| 412 | public function getLatestDev() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @param $latest_dev |
||
| 419 | */ |
||
| 420 | public function setLatestDev($latest_dev) |
||
| 424 | |||
| 425 | /** |
||
| 426 | * @return mixed |
||
| 427 | */ |
||
| 428 | public function getLatestVersion() |
||
| 432 | |||
| 433 | /** |
||
| 434 | * @param $latest_version |
||
| 435 | */ |
||
| 436 | public function setLatestVersion($latest_version) |
||
| 440 | |||
| 441 | /** |
||
| 442 | * @return string |
||
| 443 | */ |
||
| 444 | public function getName() |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @return string |
||
| 451 | */ |
||
| 452 | public function getProject() |
||
| 456 | |||
| 457 | /** |
||
| 458 | * @return int |
||
| 459 | */ |
||
| 460 | public function getProjectStatus() |
||
| 464 | |||
| 465 | /** |
||
| 466 | * @param int $project_status |
||
| 467 | */ |
||
| 468 | public function setProjectStatus($project_status) |
||
| 472 | |||
| 473 | /** |
||
| 474 | * @return string |
||
| 475 | */ |
||
| 476 | public function getReason() |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @param string $reason |
||
| 483 | */ |
||
| 484 | public function setReason($reason) |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @return mixed |
||
| 491 | */ |
||
| 492 | public function getRecommended() |
||
| 496 | |||
| 497 | /** |
||
| 498 | * @param $recommended |
||
| 499 | */ |
||
| 500 | public function setRecommended($recommended) |
||
| 504 | |||
| 505 | /** |
||
| 506 | * @return Release[] |
||
| 507 | */ |
||
| 508 | public function getReleases() |
||
| 512 | |||
| 513 | /** |
||
| 514 | * @param Release[] $releases |
||
| 515 | */ |
||
| 516 | public function setReleases($releases) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @param string $release |
||
| 523 | * |
||
| 524 | * @return Release|false |
||
| 525 | */ |
||
| 526 | public function getRelease($release) |
||
| 534 | |||
| 535 | /** |
||
| 536 | * @return Release[] |
||
| 537 | */ |
||
| 538 | public function getSecurityUpdates() |
||
| 542 | |||
| 543 | /** |
||
| 544 | * @param Release[] $security_updates |
||
| 545 | */ |
||
| 546 | public function setSecurityUpdates($security_updates) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * @return int |
||
| 553 | */ |
||
| 554 | public function getStatus() |
||
| 558 | |||
| 559 | /** |
||
| 560 | * @param int $status |
||
| 561 | */ |
||
| 562 | public function setStatus($status) |
||
| 566 | |||
| 567 | /** |
||
| 568 | * @return string |
||
| 569 | */ |
||
| 570 | public function getStatusUrl() |
||
| 574 | |||
| 575 | /** |
||
| 576 | * @param string $status_url |
||
| 577 | */ |
||
| 578 | public function setStatusUrl($status_url) |
||
| 582 | |||
| 583 | /** |
||
| 584 | * @return string |
||
| 585 | */ |
||
| 586 | public function getVersion() |
||
| 590 | |||
| 591 | /** |
||
| 592 | * @return bool |
||
| 593 | */ |
||
| 594 | public function hasSecurityUpdates() |
||
| 598 | |||
| 599 | /** |
||
| 600 | * @param array $data |
||
| 601 | */ |
||
| 602 | public function setDetails($data) |
||
| 614 | |||
| 615 | /** |
||
| 616 | * @param string $version |
||
| 617 | * @param Release $release |
||
| 618 | */ |
||
| 619 | public function setRelease($version, Release $release) |
||
| 623 | } |
||
| 624 |