Complex classes like Video 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 Video, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 4 | class Video |
||
| 5 | { |
||
| 6 | /** |
||
| 7 | * @var string |
||
| 8 | */ |
||
| 9 | protected $broadcast_type; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $broadcast_id; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $recorded_at; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $created_at; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var stdClass |
||
| 28 | */ |
||
| 29 | protected $resolutions; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $description; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | protected $thumbnails; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | protected $tag_list; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | protected $delete_at; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $vod_type; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var bool |
||
| 58 | */ |
||
| 59 | protected $is_muted; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | protected $preview; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | protected $channel; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | protected $length; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var string |
||
| 78 | */ |
||
| 79 | protected $status; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var string |
||
| 83 | */ |
||
| 84 | protected $views; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var string |
||
| 88 | */ |
||
| 89 | protected $title; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var string |
||
| 93 | */ |
||
| 94 | protected $game; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var string |
||
| 98 | */ |
||
| 99 | protected $url; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var stdClass |
||
| 103 | */ |
||
| 104 | protected $fps; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var string $id |
||
| 108 | */ |
||
| 109 | protected $id; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @return string |
||
| 113 | */ |
||
| 114 | public function getBroadcastType() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @param string $broadcast_type |
||
| 121 | */ |
||
| 122 | public function setBroadcastType($broadcast_type) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | public function getBroadcastId() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param string $broadcast_id |
||
| 137 | */ |
||
| 138 | public function setBroadcastId($broadcast_id) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @return string |
||
| 145 | */ |
||
| 146 | public function getRecordedAt() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @param string $recorded_at |
||
| 153 | */ |
||
| 154 | public function setRecordedAt($recorded_at) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @return string |
||
| 161 | */ |
||
| 162 | public function getCreatedAt() |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @param string $created_at |
||
| 169 | */ |
||
| 170 | public function setCreatedAt($created_at) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return stdClass |
||
| 177 | */ |
||
| 178 | public function getResolutions() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param stdClass $resolutions |
||
| 185 | */ |
||
| 186 | public function setResolutions($resolutions) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @return string |
||
| 193 | */ |
||
| 194 | public function getDescription() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param string $description |
||
| 201 | */ |
||
| 202 | public function setDescription($description) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @return array |
||
| 209 | */ |
||
| 210 | public function getThumbnails() |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @param array $thumbnails |
||
| 217 | */ |
||
| 218 | public function setThumbnails($thumbnails) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @return string |
||
| 225 | */ |
||
| 226 | public function getTagList() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @param string $tag_list |
||
| 233 | */ |
||
| 234 | public function setTagList($tag_list) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | public function getDeleteAt() |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @param string $delete_at |
||
| 249 | */ |
||
| 250 | public function setDeleteAt($delete_at) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | public function getVodType() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @param string $vod_type |
||
| 265 | */ |
||
| 266 | public function setVodType($vod_type) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @return boolean |
||
| 273 | */ |
||
| 274 | public function isIsMuted() |
||
| 278 | |||
| 279 | /** |
||
| 280 | * @param boolean $is_muted |
||
| 281 | */ |
||
| 282 | public function setIsMuted($is_muted) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @return string |
||
| 289 | */ |
||
| 290 | public function getPreview() |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @param string $preview |
||
| 297 | */ |
||
| 298 | public function setPreview($preview) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * @return string |
||
| 305 | */ |
||
| 306 | public function getChannel() |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @param string $channel |
||
| 313 | */ |
||
| 314 | public function setChannel($channel) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @return string |
||
| 321 | */ |
||
| 322 | public function getLength() |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @param string $length |
||
| 329 | */ |
||
| 330 | public function setLength($length) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @return string |
||
| 337 | */ |
||
| 338 | public function getStatus() |
||
| 342 | |||
| 343 | /** |
||
| 344 | * @param string $status |
||
| 345 | */ |
||
| 346 | public function setStatus($status) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * @return string |
||
| 353 | */ |
||
| 354 | public function getViews() |
||
| 358 | |||
| 359 | /** |
||
| 360 | * @param string $views |
||
| 361 | */ |
||
| 362 | public function setViews($views) |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @return string |
||
| 369 | */ |
||
| 370 | public function getTitle() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @param string $title |
||
| 377 | */ |
||
| 378 | public function setTitle($title) |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @return string |
||
| 385 | */ |
||
| 386 | public function getGame() |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @param string $game |
||
| 393 | */ |
||
| 394 | public function setGame($game) |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @return string |
||
| 401 | */ |
||
| 402 | public function getUrl() |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @param string $url |
||
| 409 | */ |
||
| 410 | public function setUrl($url) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @return stdClass |
||
| 417 | */ |
||
| 418 | public function getFps() |
||
| 422 | |||
| 423 | /** |
||
| 424 | * @param stdClass $fps |
||
| 425 | */ |
||
| 426 | public function setFps($fps) |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @return string |
||
| 433 | */ |
||
| 434 | public function getId() |
||
| 438 | |||
| 439 | /** |
||
| 440 | * @param string $id |
||
| 441 | */ |
||
| 442 | public function setId($id) |
||
| 446 | |||
| 447 | } |