Complex classes like LeadData 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 LeadData, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class LeadData |
||
| 8 | { |
||
| 9 | private $firstname; |
||
| 10 | private $lastname; |
||
| 11 | private $phone; |
||
| 12 | private $cellphone; |
||
| 13 | private $email; |
||
| 14 | private $contact_type_id; |
||
| 15 | private $business_type_id; |
||
| 16 | private $notes; |
||
| 17 | private $origin_id; |
||
| 18 | private $suborigin_id; |
||
| 19 | private $assigned_user; |
||
| 20 | private $car_brand; |
||
| 21 | private $car_modelo; |
||
| 22 | private $city; |
||
| 23 | private $province; |
||
| 24 | private $country; |
||
| 25 | private $vendor_name; |
||
| 26 | private $vendor_email; |
||
| 27 | private $vendor_phone; |
||
| 28 | private $provider_service; |
||
| 29 | private $provider_url; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * LeadData constructor. |
||
| 33 | * |
||
| 34 | * @param array $data |
||
| 35 | */ |
||
| 36 | public function __construct($data = []) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Object to array |
||
| 48 | * |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | public function toArray() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Validate |
||
| 81 | * |
||
| 82 | * @throws InvalidArgumentException |
||
| 83 | */ |
||
| 84 | private function validate() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Set |
||
| 116 | * |
||
| 117 | * @param $key |
||
| 118 | * @param string $value |
||
| 119 | */ |
||
| 120 | private function set($key, $value = "") |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @return mixed |
||
| 130 | */ |
||
| 131 | public function getFirstname() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @param $firstname |
||
| 138 | * |
||
| 139 | * @return $this |
||
| 140 | */ |
||
| 141 | public function setFirstname($firstname) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return mixed |
||
| 149 | */ |
||
| 150 | public function getLastname() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param $lastname |
||
| 157 | * |
||
| 158 | * @return $this |
||
| 159 | */ |
||
| 160 | public function setLastname($lastname) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @return mixed |
||
| 168 | */ |
||
| 169 | public function getPhone() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param $phone |
||
| 176 | * |
||
| 177 | * @return $this |
||
| 178 | */ |
||
| 179 | public function setPhone($phone) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @return mixed |
||
| 187 | */ |
||
| 188 | public function getCellphone() |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param $cellphone |
||
| 195 | * |
||
| 196 | * @return $this |
||
| 197 | */ |
||
| 198 | public function setCellphone($cellphone) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return mixed |
||
| 206 | */ |
||
| 207 | public function getEmail() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param $email |
||
| 214 | * |
||
| 215 | * @return $this |
||
| 216 | */ |
||
| 217 | public function setEmail($email) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @return mixed |
||
| 225 | */ |
||
| 226 | public function getContactTypeId() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @param $contact_type_id |
||
| 233 | * |
||
| 234 | * @return $this |
||
| 235 | */ |
||
| 236 | public function setContactTypeId($contact_type_id) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return mixed |
||
| 244 | */ |
||
| 245 | public function getBusinessTypeId() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @param $business_type_id |
||
| 252 | * |
||
| 253 | * @return $this |
||
| 254 | */ |
||
| 255 | public function setBusinessTypeId($business_type_id) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @return mixed |
||
| 263 | */ |
||
| 264 | public function getNotes() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param $notes |
||
| 271 | * |
||
| 272 | * @return $this |
||
| 273 | */ |
||
| 274 | public function setNotes($notes) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @return mixed |
||
| 282 | */ |
||
| 283 | public function getOriginId() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param $origin_id |
||
| 290 | * |
||
| 291 | * @return $this |
||
| 292 | */ |
||
| 293 | public function setOriginId($origin_id) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @return mixed |
||
| 301 | */ |
||
| 302 | public function getSuboriginId() |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @param $suborigin_id |
||
| 309 | * |
||
| 310 | * @return $this |
||
| 311 | */ |
||
| 312 | public function setSuboriginId($suborigin_id) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @return mixed |
||
| 320 | */ |
||
| 321 | public function getAssignedUser() |
||
| 325 | |||
| 326 | /** |
||
| 327 | * @param $assigned_user |
||
| 328 | * |
||
| 329 | * @return $this |
||
| 330 | */ |
||
| 331 | public function setAssignedUser($assigned_user) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @return mixed |
||
| 339 | */ |
||
| 340 | public function getCarBrand() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @param $car_brand |
||
| 347 | * |
||
| 348 | * @return $this |
||
| 349 | */ |
||
| 350 | public function setCarBrand($car_brand) |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @return mixed |
||
| 358 | */ |
||
| 359 | public function getCarModelo() |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @param $car_modelo |
||
| 366 | * |
||
| 367 | * @return $this |
||
| 368 | */ |
||
| 369 | public function setCarModelo($car_modelo) |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @return mixed |
||
| 377 | */ |
||
| 378 | public function getCity() |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @param $city |
||
| 385 | * |
||
| 386 | * @return $this |
||
| 387 | */ |
||
| 388 | public function setCity($city) |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @return mixed |
||
| 396 | */ |
||
| 397 | public function getProvince() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @param $province |
||
| 404 | * |
||
| 405 | * @return $this |
||
| 406 | */ |
||
| 407 | public function setProvince($province) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @return mixed |
||
| 415 | */ |
||
| 416 | public function getCountry() |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @param $country |
||
| 423 | * |
||
| 424 | * @return $this |
||
| 425 | */ |
||
| 426 | public function setCountry($country) |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @return mixed |
||
| 434 | */ |
||
| 435 | public function getVendorName() |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @param $vendor_name |
||
| 442 | * |
||
| 443 | * @return $this |
||
| 444 | */ |
||
| 445 | public function setVendorName($vendor_name) |
||
| 450 | |||
| 451 | /** |
||
| 452 | * @return mixed |
||
| 453 | */ |
||
| 454 | public function getVendorEmail() |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @param $vendor_email |
||
| 461 | * |
||
| 462 | * @return $this |
||
| 463 | */ |
||
| 464 | public function setVendorEmail($vendor_email) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @return mixed |
||
| 472 | */ |
||
| 473 | public function getVendorPhone() |
||
| 477 | |||
| 478 | /** |
||
| 479 | * @param $vendor_phone |
||
| 480 | * |
||
| 481 | * @return $this |
||
| 482 | */ |
||
| 483 | public function setVendorPhone($vendor_phone) |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @return mixed |
||
| 491 | */ |
||
| 492 | public function getProviderService() |
||
| 496 | |||
| 497 | /** |
||
| 498 | * @param $provider_service |
||
| 499 | * |
||
| 500 | * @return $this |
||
| 501 | */ |
||
| 502 | public function setProviderService($provider_service) |
||
| 507 | |||
| 508 | /** |
||
| 509 | * @return mixed |
||
| 510 | */ |
||
| 511 | public function getProviderUrl() |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @param $provider_url |
||
| 518 | * |
||
| 519 | * @return $this |
||
| 520 | */ |
||
| 521 | public function setProviderUrl($provider_url) |
||
| 526 | } |
||
| 527 |