Complex classes like DraftOrder 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 DraftOrder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class DraftOrder extends Model |
||
13 | { |
||
14 | use AdminGraphqlApiId; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $note; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $email; |
||
25 | |||
26 | /** |
||
27 | * @var boolean |
||
28 | */ |
||
29 | protected $taxesIncluded; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $currency; |
||
35 | |||
36 | /** |
||
37 | * @var \DateTimeInterface |
||
38 | */ |
||
39 | protected $invoiceSentAt; |
||
40 | |||
41 | /** |
||
42 | * @var \DateTimeInterface |
||
43 | */ |
||
44 | protected $createdAt; |
||
45 | |||
46 | /** |
||
47 | * @var \DateTimeInterface |
||
48 | */ |
||
49 | protected $updatedAt; |
||
50 | |||
51 | /** |
||
52 | * @var boolean |
||
53 | */ |
||
54 | protected $taxExempt; |
||
55 | |||
56 | /** |
||
57 | * @var \DateTimeInterface |
||
58 | */ |
||
59 | protected $completedAt; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $name; |
||
65 | |||
66 | /** |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $status; |
||
70 | |||
71 | /** |
||
72 | * @var LineItem[] |
||
73 | */ |
||
74 | protected $lineItems = []; |
||
75 | |||
76 | /** |
||
77 | * @var Address |
||
78 | */ |
||
79 | protected $shippingAddress; |
||
80 | |||
81 | /** |
||
82 | * @var Address |
||
83 | */ |
||
84 | protected $billingAddress; |
||
85 | |||
86 | /** |
||
87 | * @var string |
||
88 | */ |
||
89 | protected $invoiceUrl; |
||
90 | |||
91 | /** |
||
92 | * @var array |
||
93 | */ |
||
94 | protected $appliedDiscount; |
||
95 | |||
96 | /** |
||
97 | * @var int |
||
98 | */ |
||
99 | protected $orderId; |
||
100 | |||
101 | /** |
||
102 | * @var array |
||
103 | */ |
||
104 | protected $shippingLine; |
||
105 | |||
106 | /** |
||
107 | * @var TaxLine[] |
||
108 | */ |
||
109 | protected $taxLines; |
||
110 | |||
111 | /** |
||
112 | * @var string |
||
113 | */ |
||
114 | protected $tag; |
||
115 | |||
116 | /** |
||
117 | * @var string |
||
118 | */ |
||
119 | protected $noteAttributes; |
||
120 | |||
121 | /** |
||
122 | * @var float |
||
123 | */ |
||
124 | protected $totalPrice; |
||
125 | |||
126 | /** |
||
127 | * @var float |
||
128 | */ |
||
129 | protected $subtotalPrice; |
||
130 | |||
131 | /** |
||
132 | * @var float |
||
133 | */ |
||
134 | protected $totalTax; |
||
135 | |||
136 | /** |
||
137 | * @var Customer |
||
138 | */ |
||
139 | protected $customer; |
||
140 | |||
141 | /** |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getNote() |
||
148 | |||
149 | /** |
||
150 | * @param string $note |
||
151 | */ |
||
152 | public function setNote($note) |
||
156 | |||
157 | /** |
||
158 | * @return string |
||
159 | */ |
||
160 | public function getEmail() |
||
164 | |||
165 | /** |
||
166 | * @param string $email |
||
167 | */ |
||
168 | public function setEmail($email) |
||
172 | |||
173 | /** |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function isTaxesIncluded() |
||
180 | |||
181 | /** |
||
182 | * @param bool $taxesIncluded |
||
183 | */ |
||
184 | public function setTaxesIncluded($taxesIncluded) |
||
188 | |||
189 | /** |
||
190 | * @return string |
||
191 | */ |
||
192 | public function getCurrency() |
||
196 | |||
197 | /** |
||
198 | * @param string $currency |
||
199 | */ |
||
200 | public function setCurrency($currency) |
||
204 | |||
205 | /** |
||
206 | * @return \DateTimeInterface |
||
207 | */ |
||
208 | public function getInvoiceSentAt() |
||
212 | |||
213 | /** |
||
214 | * @param \DateTimeInterface $invoiceSentAt |
||
215 | */ |
||
216 | public function setInvoiceSentAt($invoiceSentAt) |
||
220 | |||
221 | /** |
||
222 | * @return \DateTimeInterface |
||
223 | */ |
||
224 | public function getCreatedAt() |
||
228 | |||
229 | /** |
||
230 | * @param \DateTimeInterface $createdAt |
||
231 | */ |
||
232 | public function setCreatedAt($createdAt) |
||
236 | |||
237 | /** |
||
238 | * @return \DateTimeInterface |
||
239 | */ |
||
240 | public function getUpdatedAt() |
||
244 | |||
245 | /** |
||
246 | * @param \DateTimeInterface $updatedAt |
||
247 | */ |
||
248 | public function setUpdatedAt($updatedAt) |
||
252 | |||
253 | /** |
||
254 | * @return bool |
||
255 | */ |
||
256 | public function isTaxExempt() |
||
260 | |||
261 | /** |
||
262 | * @param bool $taxExempt |
||
263 | */ |
||
264 | public function setTaxExempt($taxExempt) |
||
268 | |||
269 | /** |
||
270 | * @return \DateTimeInterface |
||
271 | */ |
||
272 | public function getCompletedAt() |
||
276 | |||
277 | /** |
||
278 | * @param \DateTimeInterface $completedAt |
||
279 | */ |
||
280 | public function setCompletedAt($completedAt) |
||
284 | |||
285 | /** |
||
286 | * @return string |
||
287 | */ |
||
288 | public function getName() |
||
292 | |||
293 | /** |
||
294 | * @param string $name |
||
295 | */ |
||
296 | public function setName($name) |
||
300 | |||
301 | /** |
||
302 | * @return string |
||
303 | */ |
||
304 | public function getStatus() |
||
308 | |||
309 | /** |
||
310 | * @param string $status |
||
311 | */ |
||
312 | public function setStatus($status) |
||
316 | |||
317 | /** |
||
318 | * @return LineItem[] |
||
319 | */ |
||
320 | public function getLineItems() |
||
324 | |||
325 | /** |
||
326 | * @param LineItem[] $lineItems |
||
327 | */ |
||
328 | public function setLineItems($lineItems) |
||
332 | |||
333 | /** |
||
334 | * @return Address |
||
335 | */ |
||
336 | public function getShippingAddress() |
||
340 | |||
341 | /** |
||
342 | * @param Address $shippingAddress |
||
343 | */ |
||
344 | public function setShippingAddress($shippingAddress) |
||
348 | |||
349 | /** |
||
350 | * @return Address |
||
351 | */ |
||
352 | public function getBillingAddress() |
||
356 | |||
357 | /** |
||
358 | * @param Address $billingAddress |
||
359 | */ |
||
360 | public function setBillingAddress($billingAddress) |
||
364 | |||
365 | /** |
||
366 | * @return string |
||
367 | */ |
||
368 | public function getInvoiceUrl() |
||
372 | |||
373 | /** |
||
374 | * @param string $invoiceUrl |
||
375 | */ |
||
376 | public function setInvoiceUrl($invoiceUrl) |
||
380 | |||
381 | /** |
||
382 | * @return array |
||
383 | */ |
||
384 | public function getAppliedDiscount() |
||
388 | |||
389 | /** |
||
390 | * @param array $appliedDiscount |
||
391 | */ |
||
392 | public function setAppliedDiscount($appliedDiscount) |
||
396 | |||
397 | /** |
||
398 | * @return int |
||
399 | */ |
||
400 | public function getOrderId() |
||
404 | |||
405 | /** |
||
406 | * @param int $orderId |
||
407 | */ |
||
408 | public function setOrderId($orderId) |
||
412 | |||
413 | /** |
||
414 | * @return array |
||
415 | */ |
||
416 | public function getShippingLine() |
||
420 | |||
421 | /** |
||
422 | * @param array $shippingLine |
||
423 | */ |
||
424 | public function setShippingLine($shippingLine) |
||
428 | |||
429 | /** |
||
430 | * @return array |
||
431 | */ |
||
432 | public function getTaxLines() |
||
436 | |||
437 | /** |
||
438 | * @param array $taxLines |
||
439 | */ |
||
440 | public function setTaxLines($taxLines) |
||
444 | |||
445 | /** |
||
446 | * @return string |
||
447 | */ |
||
448 | public function getTag() |
||
452 | |||
453 | /** |
||
454 | * @param string $tag |
||
455 | */ |
||
456 | public function setTag($tag) |
||
460 | |||
461 | /** |
||
462 | * @return string |
||
463 | */ |
||
464 | public function getNoteAttributes() |
||
468 | |||
469 | /** |
||
470 | * @param string $noteAttributes |
||
471 | */ |
||
472 | public function setNoteAttributes($noteAttributes) |
||
476 | |||
477 | /** |
||
478 | * @return float |
||
479 | */ |
||
480 | public function getTotalPrice() |
||
484 | |||
485 | /** |
||
486 | * @param float $totalPrice |
||
487 | */ |
||
488 | public function setTotalPrice($totalPrice) |
||
492 | |||
493 | /** |
||
494 | * @return float |
||
495 | */ |
||
496 | public function getSubtotalPrice() |
||
500 | |||
501 | /** |
||
502 | * @param float $subtotalPrice |
||
503 | */ |
||
504 | public function setSubtotalPrice($subtotalPrice) |
||
508 | |||
509 | /** |
||
510 | * @return float |
||
511 | */ |
||
512 | public function getTotalTax() |
||
516 | |||
517 | /** |
||
518 | * @param float $totalTax |
||
519 | */ |
||
520 | public function setTotalTax($totalTax) |
||
524 | |||
525 | /** |
||
526 | * @return Customer |
||
527 | */ |
||
528 | public function getCustomer() |
||
532 | |||
533 | /** |
||
534 | * @param Customer $customer |
||
535 | */ |
||
536 | public function setCustomer($customer) |
||
540 | } |