Complex classes like Ad 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 Ad, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class Ad extends Entity |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | private $id = ''; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | private $city = ''; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | private $content = ''; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var District |
||
| 39 | */ |
||
| 40 | private $district; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var Email |
||
| 44 | */ |
||
| 45 | private $email; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var \DateTime |
||
| 49 | */ |
||
| 50 | private $modify; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | private $operation = ''; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | private $payment = ''; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var Phone |
||
| 64 | */ |
||
| 65 | private $phone; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var array |
||
| 69 | */ |
||
| 70 | private $pictures = []; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var Price |
||
| 74 | */ |
||
| 75 | private $price; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | private $region = ''; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var string |
||
| 84 | */ |
||
| 85 | private $status = ''; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var string |
||
| 89 | */ |
||
| 90 | private $title = ''; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var string |
||
| 94 | */ |
||
| 95 | private $type = ''; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Get Id |
||
| 99 | * |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | public function getId() |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Set Id |
||
| 114 | * |
||
| 115 | * @param string $id |
||
| 116 | * |
||
| 117 | * @return Ad |
||
| 118 | */ |
||
| 119 | public function setId($id) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Get City |
||
| 127 | * |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | public function getCity() |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Set City |
||
| 142 | * |
||
| 143 | * @param string $city |
||
| 144 | * |
||
| 145 | * @return Ad |
||
| 146 | */ |
||
| 147 | public function setCity($city) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Get Content |
||
| 155 | * |
||
| 156 | * @return string |
||
| 157 | */ |
||
| 158 | public function getContent() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Set Content |
||
| 170 | * |
||
| 171 | * @param string $content |
||
| 172 | * |
||
| 173 | * @return Ad |
||
| 174 | */ |
||
| 175 | public function setContent($content) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Get Email |
||
| 183 | * |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | public function getEmail() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Set Email |
||
| 198 | * |
||
| 199 | * @param Email $email |
||
| 200 | * |
||
| 201 | * @return Ad |
||
| 202 | */ |
||
| 203 | public function setEmail(Email $email) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Get District |
||
| 211 | * |
||
| 212 | * @return District |
||
| 213 | */ |
||
| 214 | public function getDistrict() |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Set District |
||
| 221 | * |
||
| 222 | * @param District $district |
||
| 223 | * |
||
| 224 | * @return Ad |
||
| 225 | */ |
||
| 226 | public function setDistrict(District $district) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Get Modify |
||
| 234 | * |
||
| 235 | * @return \DateTime |
||
| 236 | */ |
||
| 237 | public function getModify() |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Set Modify |
||
| 249 | * |
||
| 250 | * @param \DateTime $modify |
||
| 251 | * |
||
| 252 | * @return Ad |
||
| 253 | */ |
||
| 254 | public function setModify($modify) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Get Operation |
||
| 262 | * |
||
| 263 | * @return string |
||
| 264 | */ |
||
| 265 | public function getOperation() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Set Operation |
||
| 277 | * |
||
| 278 | * @param string $operation |
||
| 279 | * |
||
| 280 | * @return Ad |
||
| 281 | */ |
||
| 282 | public function setOperation($operation) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Set Payment |
||
| 290 | * |
||
| 291 | * @param string $payment |
||
| 292 | * |
||
| 293 | * @return Ad |
||
| 294 | */ |
||
| 295 | public function setPayment(string $payment) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Get Payment |
||
| 303 | * |
||
| 304 | * @return string |
||
| 305 | */ |
||
| 306 | public function getPayment() |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Get Phone |
||
| 313 | * |
||
| 314 | * @return Phone |
||
| 315 | */ |
||
| 316 | public function getPhone() |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Set Phone |
||
| 328 | * |
||
| 329 | * @param Phone $phone |
||
| 330 | * |
||
| 331 | * @return Ad |
||
| 332 | */ |
||
| 333 | public function setPhone(Phone $phone) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Add Picture |
||
| 341 | * |
||
| 342 | * @param Picture $picture |
||
| 343 | * |
||
| 344 | * @return Ad |
||
| 345 | */ |
||
| 346 | public function addPicture(Picture $picture) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Get Pictures |
||
| 354 | * |
||
| 355 | * @return array |
||
| 356 | */ |
||
| 357 | public function getPictures() |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Set Pictures |
||
| 369 | * |
||
| 370 | * @param array $pictures |
||
| 371 | * |
||
| 372 | * @return Ad |
||
| 373 | */ |
||
| 374 | public function setPictures($pictures) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Get Price |
||
| 382 | * |
||
| 383 | * @return Price |
||
| 384 | */ |
||
| 385 | public function getPrice() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Set Price |
||
| 397 | * |
||
| 398 | * @param Price $price |
||
| 399 | * |
||
| 400 | * @return Ad |
||
| 401 | */ |
||
| 402 | public function setPrice($price) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Get Region |
||
| 410 | * |
||
| 411 | * @return string |
||
| 412 | */ |
||
| 413 | public function getRegion() |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Set Region |
||
| 425 | * |
||
| 426 | * @param string $region |
||
| 427 | * |
||
| 428 | * @return Ad |
||
| 429 | */ |
||
| 430 | public function setRegion($region) |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Get Status |
||
| 438 | * |
||
| 439 | * @return string |
||
| 440 | */ |
||
| 441 | public function getStatus() |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Set Status |
||
| 453 | * |
||
| 454 | * @param string $status |
||
| 455 | * |
||
| 456 | * @return Ad |
||
| 457 | */ |
||
| 458 | public function setStatus($status) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Get Title |
||
| 466 | * |
||
| 467 | * @return string |
||
| 468 | */ |
||
| 469 | public function getTitle() |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Set Title |
||
| 481 | * |
||
| 482 | * @param string $title |
||
| 483 | * |
||
| 484 | * @return Ad |
||
| 485 | */ |
||
| 486 | public function setTitle($title) |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Get Type |
||
| 494 | * |
||
| 495 | * @return string |
||
| 496 | */ |
||
| 497 | public function getType() |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Set Type |
||
| 509 | * |
||
| 510 | * @param string $type |
||
| 511 | * |
||
| 512 | * @return Ad |
||
| 513 | */ |
||
| 514 | public function setType($type) |
||
| 519 | } |
||
| 520 |