Complex classes like Lead 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 Lead, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class Lead extends Model |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @var integer |
||
16 | */ |
||
17 | protected $id; |
||
18 | |||
19 | /** |
||
20 | * @var integer |
||
21 | */ |
||
22 | protected $contactId; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $name; |
||
28 | |||
29 | /** |
||
30 | * @var integer |
||
31 | */ |
||
32 | protected $funnelId; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $source; |
||
38 | |||
39 | /** |
||
40 | * @var integer |
||
41 | */ |
||
42 | protected $ownerId; |
||
43 | |||
44 | /** |
||
45 | * @var \DateTime |
||
46 | */ |
||
47 | protected $createdAt; |
||
48 | |||
49 | /** |
||
50 | * @var Payment[] |
||
51 | */ |
||
52 | protected $payments = []; |
||
53 | |||
54 | /** |
||
55 | * @var Custom[] |
||
56 | */ |
||
57 | protected $customs = []; |
||
58 | |||
59 | /** |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $options = []; |
||
63 | |||
64 | |||
65 | /** |
||
66 | * Lead constructor. |
||
67 | * |
||
68 | * @param array $leadData |
||
69 | */ |
||
70 | public function __construct(array $leadData = []) |
||
113 | |||
114 | |||
115 | /** |
||
116 | * @return array |
||
117 | */ |
||
118 | public function toArray() |
||
153 | |||
154 | |||
155 | /** |
||
156 | * @return bool |
||
157 | * @throws LPTrackerSDKException |
||
158 | */ |
||
159 | public function validate() |
||
179 | |||
180 | |||
181 | /** |
||
182 | * @return int |
||
183 | */ |
||
184 | public function getId() |
||
188 | |||
189 | |||
190 | /** |
||
191 | * @return int |
||
192 | */ |
||
193 | public function getContactId() |
||
197 | |||
198 | |||
199 | /** |
||
200 | * @return string |
||
201 | */ |
||
202 | public function getName() |
||
206 | |||
207 | |||
208 | /** |
||
209 | * @param string $name |
||
210 | * |
||
211 | * @return $this |
||
212 | */ |
||
213 | public function setName($name) |
||
219 | |||
220 | |||
221 | /** |
||
222 | * @return int |
||
223 | */ |
||
224 | public function getFunnelId() |
||
228 | |||
229 | |||
230 | /** |
||
231 | * @param int $funnelId |
||
232 | * |
||
233 | * @return $this |
||
234 | */ |
||
235 | public function setFunnelId($funnelId) |
||
241 | |||
242 | |||
243 | /** |
||
244 | * @return string |
||
245 | */ |
||
246 | public function getSource() |
||
250 | |||
251 | |||
252 | /** |
||
253 | * @param string $source |
||
254 | * |
||
255 | * @return $this |
||
256 | */ |
||
257 | public function setSource($source) |
||
263 | |||
264 | |||
265 | /** |
||
266 | * @return Payment[] |
||
267 | */ |
||
268 | public function getPayments() |
||
272 | |||
273 | |||
274 | /** |
||
275 | * @param array $payments |
||
276 | * |
||
277 | * @return $this |
||
278 | */ |
||
279 | public function setPayments(array $payments) |
||
285 | |||
286 | |||
287 | /** |
||
288 | * @param Payment $payment |
||
289 | * |
||
290 | * @return $this |
||
291 | */ |
||
292 | public function addPayment(Payment $payment) |
||
298 | |||
299 | |||
300 | /** |
||
301 | * @return int |
||
302 | */ |
||
303 | public function getOwnerId() |
||
307 | |||
308 | |||
309 | /** |
||
310 | * @param int $ownerId |
||
311 | * |
||
312 | * @return $this |
||
313 | */ |
||
314 | public function setOwnerId($ownerId) |
||
320 | |||
321 | |||
322 | /** |
||
323 | * @return Custom[] |
||
324 | */ |
||
325 | public function getCustoms() |
||
329 | |||
330 | |||
331 | /** |
||
332 | * @param Custom[] $customs |
||
333 | * |
||
334 | * @return $this |
||
335 | */ |
||
336 | public function setCustoms(array $customs) |
||
342 | |||
343 | |||
344 | /** |
||
345 | * @param Custom $custom |
||
346 | * |
||
347 | * @return $this |
||
348 | */ |
||
349 | public function addCustom(Custom $custom) |
||
355 | |||
356 | |||
357 | /** |
||
358 | * @return \DateTime |
||
359 | */ |
||
360 | public function getCreatedAt() |
||
364 | |||
365 | |||
366 | /** |
||
367 | * @param \DateTime $createdAt |
||
368 | * |
||
369 | * @return $this |
||
370 | */ |
||
371 | public function setCreatedAt($createdAt) |
||
377 | } |