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