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 |
||
| 21 | class Ad extends Entity |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | private $id = ''; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $ads_type = ''; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | private $city = ''; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $content = ''; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var District |
||
| 45 | */ |
||
| 46 | private $district; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var Email |
||
| 50 | */ |
||
| 51 | private $email; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var \DateTime |
||
| 55 | */ |
||
| 56 | private $modify; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | private $operation = ''; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | private $payment = ''; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var Phone |
||
| 70 | */ |
||
| 71 | private $phone; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var array |
||
| 75 | */ |
||
| 76 | private $pictures = []; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var Price |
||
| 80 | */ |
||
| 81 | private $price; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var string |
||
| 85 | */ |
||
| 86 | private $region = ''; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var string |
||
| 90 | */ |
||
| 91 | private $status = ''; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var string |
||
| 95 | */ |
||
| 96 | private $title = ''; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var string |
||
| 100 | */ |
||
| 101 | private $type = ''; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Get Id |
||
| 105 | * |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | 6 | public function getId() |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Set Id |
||
| 120 | * |
||
| 121 | * @param string $id |
||
| 122 | * |
||
| 123 | * @return Ad |
||
| 124 | */ |
||
| 125 | 4 | public function setId($id) |
|
| 130 | |||
| 131 | /** |
||
| 132 | * Get Ads Type |
||
| 133 | * |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | 6 | public function getAdsType() |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Set Ads Type |
||
| 148 | * |
||
| 149 | * @param string $ads_type |
||
| 150 | * |
||
| 151 | * @return Ad |
||
| 152 | */ |
||
| 153 | 4 | public function setAdsType($ads_type) |
|
| 158 | |||
| 159 | /** |
||
| 160 | * Get City |
||
| 161 | * |
||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | 6 | public function getCity() |
|
| 173 | |||
| 174 | /** |
||
| 175 | * Set City |
||
| 176 | * |
||
| 177 | * @param string $city |
||
| 178 | * |
||
| 179 | * @return Ad |
||
| 180 | */ |
||
| 181 | 4 | public function setCity($city) |
|
| 186 | |||
| 187 | /** |
||
| 188 | * Get Content |
||
| 189 | * |
||
| 190 | * @return string |
||
| 191 | */ |
||
| 192 | 6 | public function getContent() |
|
| 201 | |||
| 202 | /** |
||
| 203 | * Set Content |
||
| 204 | * |
||
| 205 | * @param string $content |
||
| 206 | * |
||
| 207 | * @return Ad |
||
| 208 | */ |
||
| 209 | 4 | public function setContent($content) |
|
| 214 | |||
| 215 | /** |
||
| 216 | * Get Email |
||
| 217 | * |
||
| 218 | * @return string |
||
| 219 | */ |
||
| 220 | 6 | public function getEmail() |
|
| 229 | |||
| 230 | /** |
||
| 231 | * Set Email |
||
| 232 | * |
||
| 233 | * @param Email $email |
||
| 234 | * |
||
| 235 | * @return Ad |
||
| 236 | */ |
||
| 237 | 4 | public function setEmail(Email $email) |
|
| 242 | |||
| 243 | /** |
||
| 244 | * Get District |
||
| 245 | * |
||
| 246 | * @return District |
||
| 247 | */ |
||
| 248 | 1 | public function getDistrict() |
|
| 252 | |||
| 253 | /** |
||
| 254 | * Set District |
||
| 255 | * |
||
| 256 | * @param District $district |
||
| 257 | * |
||
| 258 | * @return Ad |
||
| 259 | */ |
||
| 260 | 3 | public function setDistrict(District $district) |
|
| 265 | |||
| 266 | /** |
||
| 267 | * Get Modify |
||
| 268 | * |
||
| 269 | * @return \DateTime |
||
| 270 | */ |
||
| 271 | 6 | public function getModify() |
|
| 280 | |||
| 281 | /** |
||
| 282 | * Set Modify |
||
| 283 | * |
||
| 284 | * @param \DateTime $modify |
||
| 285 | * |
||
| 286 | * @return Ad |
||
| 287 | */ |
||
| 288 | 4 | public function setModify($modify) |
|
| 293 | |||
| 294 | /** |
||
| 295 | * Get Operation |
||
| 296 | * |
||
| 297 | * @return string |
||
| 298 | */ |
||
| 299 | 6 | public function getOperation() |
|
| 308 | |||
| 309 | /** |
||
| 310 | * Set Operation |
||
| 311 | * |
||
| 312 | * @param string $operation |
||
| 313 | * |
||
| 314 | * @return Ad |
||
| 315 | */ |
||
| 316 | 4 | public function setOperation($operation) |
|
| 321 | |||
| 322 | /** |
||
| 323 | * Set Payment |
||
| 324 | * |
||
| 325 | * @param string $payment |
||
| 326 | * |
||
| 327 | * @return Ad |
||
| 328 | */ |
||
| 329 | 4 | public function setPayment($payment) |
|
| 334 | |||
| 335 | /** |
||
| 336 | * Get Payment |
||
| 337 | * |
||
| 338 | * @return string |
||
| 339 | */ |
||
| 340 | 4 | public function getPayment() |
|
| 344 | |||
| 345 | /** |
||
| 346 | * Get Phone |
||
| 347 | * |
||
| 348 | * @return Phone |
||
| 349 | */ |
||
| 350 | 6 | public function getPhone() |
|
| 359 | |||
| 360 | /** |
||
| 361 | * Set Phone |
||
| 362 | * |
||
| 363 | * @param Phone $phone |
||
| 364 | * |
||
| 365 | * @return Ad |
||
| 366 | */ |
||
| 367 | 4 | public function setPhone(Phone $phone) |
|
| 372 | |||
| 373 | /** |
||
| 374 | * Add Picture |
||
| 375 | * |
||
| 376 | * @param Picture $picture |
||
| 377 | * |
||
| 378 | * @return Ad |
||
| 379 | */ |
||
| 380 | 2 | public function addPicture(Picture $picture) |
|
| 385 | |||
| 386 | /** |
||
| 387 | * Get Pictures |
||
| 388 | * |
||
| 389 | * @return array |
||
| 390 | */ |
||
| 391 | 4 | public function getPictures() |
|
| 400 | |||
| 401 | /** |
||
| 402 | * Set Pictures |
||
| 403 | * |
||
| 404 | * @param array $pictures |
||
| 405 | * |
||
| 406 | * @return Ad |
||
| 407 | */ |
||
| 408 | public function setPictures($pictures) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Get Price |
||
| 416 | * |
||
| 417 | * @return Price |
||
| 418 | */ |
||
| 419 | 6 | public function getPrice() |
|
| 428 | |||
| 429 | /** |
||
| 430 | * Set Price |
||
| 431 | * |
||
| 432 | * @param Price $price |
||
| 433 | * |
||
| 434 | * @return Ad |
||
| 435 | */ |
||
| 436 | 4 | public function setPrice($price) |
|
| 441 | |||
| 442 | /** |
||
| 443 | * Get Region |
||
| 444 | * |
||
| 445 | * @return string |
||
| 446 | */ |
||
| 447 | 6 | public function getRegion() |
|
| 456 | |||
| 457 | /** |
||
| 458 | * Set Region |
||
| 459 | * |
||
| 460 | * @param string $region |
||
| 461 | * |
||
| 462 | * @return Ad |
||
| 463 | */ |
||
| 464 | 4 | public function setRegion($region) |
|
| 469 | |||
| 470 | /** |
||
| 471 | * Get Status |
||
| 472 | * |
||
| 473 | * @return string |
||
| 474 | */ |
||
| 475 | 6 | public function getStatus() |
|
| 484 | |||
| 485 | /** |
||
| 486 | * Set Status |
||
| 487 | * |
||
| 488 | * @param string $status |
||
| 489 | * |
||
| 490 | * @return Ad |
||
| 491 | */ |
||
| 492 | 4 | public function setStatus($status) |
|
| 497 | |||
| 498 | /** |
||
| 499 | * Get Title |
||
| 500 | * |
||
| 501 | * @return string |
||
| 502 | */ |
||
| 503 | 6 | public function getTitle() |
|
| 512 | |||
| 513 | /** |
||
| 514 | * Set Title |
||
| 515 | * |
||
| 516 | * @param string $title |
||
| 517 | * |
||
| 518 | * @return Ad |
||
| 519 | */ |
||
| 520 | 4 | public function setTitle($title) |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Get Type |
||
| 528 | * |
||
| 529 | * @return string |
||
| 530 | */ |
||
| 531 | 6 | public function getType() |
|
| 540 | |||
| 541 | /** |
||
| 542 | * Set Type |
||
| 543 | * |
||
| 544 | * @param string $type |
||
| 545 | * |
||
| 546 | * @return Ad |
||
| 547 | */ |
||
| 548 | 4 | public function setType($type) |
|
| 553 | } |
||
| 554 |