Complex classes like Channel 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 Channel, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 4 | class Channel |
||
| 5 | { |
||
| 6 | |||
| 7 | /** |
||
| 8 | * @var string |
||
| 9 | */ |
||
| 10 | protected $profile_banner_background_color; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $broadcaster_language; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $profile_banner; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $video_banner; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $display_name; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $created_at; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $updated_at; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | protected $background; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $stream_key; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $followers; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $language; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var bool |
||
| 64 | */ |
||
| 65 | protected $partner; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var string |
||
| 69 | */ |
||
| 70 | protected $banner; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | protected $mature; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | protected $status; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var int |
||
| 84 | */ |
||
| 85 | protected $delay; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var int |
||
| 89 | */ |
||
| 90 | protected $views; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var string |
||
| 94 | */ |
||
| 95 | protected $email; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var string |
||
| 99 | */ |
||
| 100 | protected $game; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var string |
||
| 104 | */ |
||
| 105 | protected $name; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var string |
||
| 109 | */ |
||
| 110 | protected $logo; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @var string |
||
| 114 | */ |
||
| 115 | protected $url; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return string |
||
| 119 | */ |
||
| 120 | public function getProfileBannerBackgroundColor() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param string $profile_banner_background_color |
||
| 127 | */ |
||
| 128 | public function setProfileBannerBackgroundColor($profile_banner_background_color) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | public function getBroadcasterLanguage() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @param string $broadcaster_language |
||
| 143 | */ |
||
| 144 | public function setBroadcasterLanguage($broadcaster_language) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @return string |
||
| 151 | */ |
||
| 152 | public function getProfileBanner() |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param string $profile_banner |
||
| 159 | */ |
||
| 160 | public function setProfileBanner($profile_banner) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return string |
||
| 167 | */ |
||
| 168 | public function getVideoBanner() |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @param string $video_banner |
||
| 175 | */ |
||
| 176 | public function setVideoBanner($video_banner) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @return string |
||
| 183 | */ |
||
| 184 | public function getDisplayName() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @param string $display_name |
||
| 191 | */ |
||
| 192 | public function setDisplayName($display_name) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | public function getCreatedAt() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param string $created_at |
||
| 207 | */ |
||
| 208 | public function setCreatedAt($created_at) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getUpdatedAt() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @param string $updated_at |
||
| 223 | */ |
||
| 224 | public function setUpdatedAt($updated_at) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return string |
||
| 231 | */ |
||
| 232 | public function getBackground() |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @param string $background |
||
| 239 | */ |
||
| 240 | public function setBackground($background) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @return string |
||
| 247 | */ |
||
| 248 | public function getStreamKey() |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @param string $stream_key |
||
| 255 | */ |
||
| 256 | public function setStreamKey($stream_key) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | public function getFollowers() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param string $followers |
||
| 271 | */ |
||
| 272 | public function setFollowers($followers) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @return string |
||
| 279 | */ |
||
| 280 | public function getLanguage() |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @param string $language |
||
| 287 | */ |
||
| 288 | public function setLanguage($language) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return boolean |
||
| 295 | */ |
||
| 296 | public function isPartner() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @param boolean $partner |
||
| 303 | */ |
||
| 304 | public function setPartner($partner) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @return string |
||
| 311 | */ |
||
| 312 | public function getBanner() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @param string $banner |
||
| 319 | */ |
||
| 320 | public function setBanner($banner) |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | public function getMature() |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @param string $mature |
||
| 335 | */ |
||
| 336 | public function setMature($mature) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @return string |
||
| 343 | */ |
||
| 344 | public function getStatus() |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param string $status |
||
| 351 | */ |
||
| 352 | public function setStatus($status) |
||
| 356 | |||
| 357 | /** |
||
| 358 | * @return int |
||
| 359 | */ |
||
| 360 | public function getDelay() |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @param int $delay |
||
| 367 | */ |
||
| 368 | public function setDelay($delay) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @return int |
||
| 375 | */ |
||
| 376 | public function getViews() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @param int $views |
||
| 383 | */ |
||
| 384 | public function setViews($views) |
||
| 388 | |||
| 389 | /** |
||
| 390 | * @return string |
||
| 391 | */ |
||
| 392 | public function getEmail() |
||
| 396 | |||
| 397 | /** |
||
| 398 | * @param string $email |
||
| 399 | */ |
||
| 400 | public function setEmail($email) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @return string |
||
| 407 | */ |
||
| 408 | public function getGame() |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @param string $game |
||
| 415 | */ |
||
| 416 | public function setGame($game) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @return string |
||
| 423 | */ |
||
| 424 | public function getName() |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @param string $name |
||
| 431 | */ |
||
| 432 | public function setName($name) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * @return string |
||
| 439 | */ |
||
| 440 | public function getLogo() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @param string $logo |
||
| 447 | */ |
||
| 448 | public function setLogo($logo) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return string |
||
| 455 | */ |
||
| 456 | public function getUrl() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @param string $url |
||
| 463 | */ |
||
| 464 | public function setUrl($url) |
||
| 468 | } |