Complex classes like BaseContent 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 BaseContent, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class BaseContent implements ContentInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var mixed |
||
| 21 | */ |
||
| 22 | protected $id; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $guid; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $headline; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $byline; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | protected $slugline; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $language; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var array |
||
| 51 | */ |
||
| 52 | protected $subjects = []; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $type; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | protected $places = []; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | protected $services = []; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | protected $located; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var int |
||
| 76 | */ |
||
| 77 | protected $urgency; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var int |
||
| 81 | */ |
||
| 82 | protected $priority; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var int |
||
| 86 | */ |
||
| 87 | protected $version; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | protected $genre; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | protected $edNote; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | protected $description; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var array |
||
| 106 | */ |
||
| 107 | protected $keywords = []; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var string |
||
| 111 | */ |
||
| 112 | protected $pubStatus = ContentInterface::STATUS_USABLE; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var string|null |
||
| 116 | */ |
||
| 117 | protected $evolvedFrom; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @return mixed |
||
| 121 | */ |
||
| 122 | public function getId() |
||
| 126 | |||
| 127 | /** |
||
| 128 | 11 | * {@inheritdoc} |
|
| 129 | */ |
||
| 130 | 11 | public function setId($id) |
|
| 134 | |||
| 135 | /** |
||
| 136 | * {@inheritdoc} |
||
| 137 | */ |
||
| 138 | public function getByline() |
||
| 142 | |||
| 143 | /** |
||
| 144 | 11 | * {@inheritdoc} |
|
| 145 | */ |
||
| 146 | 11 | public function setByline($byline) |
|
| 150 | |||
| 151 | /** |
||
| 152 | * {@inheritdoc} |
||
| 153 | */ |
||
| 154 | public function getSlugline() |
||
| 158 | |||
| 159 | /** |
||
| 160 | 11 | * {@inheritdoc} |
|
| 161 | */ |
||
| 162 | 11 | public function setSlugline($slugline) |
|
| 166 | |||
| 167 | /** |
||
| 168 | * {@inheritdoc} |
||
| 169 | */ |
||
| 170 | public function getLanguage() |
||
| 174 | |||
| 175 | /** |
||
| 176 | 11 | * {@inheritdoc} |
|
| 177 | */ |
||
| 178 | 11 | public function setLanguage($language) |
|
| 182 | |||
| 183 | /** |
||
| 184 | * {@inheritdoc} |
||
| 185 | */ |
||
| 186 | public function getSubjects() |
||
| 190 | |||
| 191 | /** |
||
| 192 | 11 | * {@inheritdoc} |
|
| 193 | */ |
||
| 194 | 11 | public function setSubjects(array $subjects = []) |
|
| 198 | |||
| 199 | /** |
||
| 200 | * {@inheritdoc} |
||
| 201 | */ |
||
| 202 | public function getType() |
||
| 206 | |||
| 207 | /** |
||
| 208 | 11 | * {@inheritdoc} |
|
| 209 | */ |
||
| 210 | 11 | public function setType($type) |
|
| 214 | |||
| 215 | /** |
||
| 216 | * {@inheritdoc} |
||
| 217 | */ |
||
| 218 | public function getPlaces() |
||
| 222 | |||
| 223 | /** |
||
| 224 | 11 | * {@inheritdoc} |
|
| 225 | */ |
||
| 226 | 11 | public function setPlaces($places) |
|
| 230 | |||
| 231 | /** |
||
| 232 | * {@inheritdoc} |
||
| 233 | */ |
||
| 234 | public function getLocated() |
||
| 238 | |||
| 239 | /** |
||
| 240 | 11 | * {@inheritdoc} |
|
| 241 | */ |
||
| 242 | 11 | public function setLocated($located) |
|
| 246 | |||
| 247 | /** |
||
| 248 | * {@inheritdoc} |
||
| 249 | */ |
||
| 250 | public function getUrgency() |
||
| 254 | |||
| 255 | /** |
||
| 256 | 11 | * {@inheritdoc} |
|
| 257 | */ |
||
| 258 | 11 | public function setUrgency($urgency) |
|
| 262 | |||
| 263 | /** |
||
| 264 | * {@inheritdoc} |
||
| 265 | */ |
||
| 266 | public function getPriority() |
||
| 270 | |||
| 271 | /** |
||
| 272 | * {@inheritdoc} |
||
| 273 | */ |
||
| 274 | public function setPriority($priority) |
||
| 278 | |||
| 279 | /** |
||
| 280 | * {@inheritdoc} |
||
| 281 | */ |
||
| 282 | public function getVersion() |
||
| 286 | |||
| 287 | /** |
||
| 288 | 11 | * {@inheritdoc} |
|
| 289 | */ |
||
| 290 | 11 | public function setVersion($version) |
|
| 294 | |||
| 295 | /** |
||
| 296 | * {@inheritdoc} |
||
| 297 | */ |
||
| 298 | public function getHeadline() |
||
| 302 | |||
| 303 | /** |
||
| 304 | 11 | * {@inheritdoc} |
|
| 305 | */ |
||
| 306 | 11 | public function setHeadline($headline) |
|
| 310 | |||
| 311 | /** |
||
| 312 | * {@inheritdoc} |
||
| 313 | */ |
||
| 314 | public function getGuid() |
||
| 318 | |||
| 319 | /** |
||
| 320 | 11 | * {@inheritdoc} |
|
| 321 | */ |
||
| 322 | 11 | public function setGuid($guid) |
|
| 326 | |||
| 327 | /** |
||
| 328 | * {@inheritdoc} |
||
| 329 | */ |
||
| 330 | public function getServices() |
||
| 334 | |||
| 335 | /** |
||
| 336 | 11 | * {@inheritdoc} |
|
| 337 | */ |
||
| 338 | 11 | public function setServices(array $services = []) |
|
| 342 | |||
| 343 | /** |
||
| 344 | * {@inheritdoc} |
||
| 345 | */ |
||
| 346 | public function getEdNote() |
||
| 350 | |||
| 351 | /** |
||
| 352 | 11 | * {@inheritdoc} |
|
| 353 | */ |
||
| 354 | 11 | public function setEdNote($edNote) |
|
| 358 | |||
| 359 | /** |
||
| 360 | * {@inheritdoc} |
||
| 361 | */ |
||
| 362 | public function getGenre() |
||
| 366 | |||
| 367 | /** |
||
| 368 | 11 | * {@inheritdoc} |
|
| 369 | */ |
||
| 370 | 11 | public function setGenre($genre) |
|
| 374 | |||
| 375 | /** |
||
| 376 | * @return string |
||
| 377 | */ |
||
| 378 | public function getDescription() |
||
| 382 | |||
| 383 | /** |
||
| 384 | 11 | * @param string $description |
|
| 385 | */ |
||
| 386 | public function setDescription($description) |
||
| 390 | 11 | ||
| 391 | 11 | /** |
|
| 392 | 11 | * {@inheritdoc} |
|
| 393 | 11 | */ |
|
| 394 | 11 | public function getMetadata() |
|
| 411 | |||
| 412 | /** |
||
| 413 | * {@inheritdoc} |
||
| 414 | */ |
||
| 415 | public function getKeywords(): array |
||
| 419 | |||
| 420 | /** |
||
| 421 | * {@inheritdoc} |
||
| 422 | */ |
||
| 423 | public function setKeywords(array $keywords) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * {@inheritdoc} |
||
| 430 | */ |
||
| 431 | public function getPubStatus(): string |
||
| 435 | |||
| 436 | /** |
||
| 437 | * {@inheritdoc} |
||
| 438 | */ |
||
| 439 | public function setPubStatus(string $pubStatus) |
||
| 443 | |||
| 444 | /** |
||
| 445 | * {@inheritdoc} |
||
| 446 | */ |
||
| 447 | public function getEvolvedFrom() |
||
| 451 | |||
| 452 | /** |
||
| 453 | * {@inheritdoc} |
||
| 454 | */ |
||
| 455 | public function setEvolvedFrom(string $evolvedFrom) |
||
| 459 | } |
||
| 460 |