Complex classes like Contract 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 Contract, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class Contract extends AbstractSObject |
||
10 | { |
||
11 | use BillingAddressTrait; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | * @JMS\Type("string") |
||
16 | * @JMS\Groups({"update", "create"}) |
||
17 | */ |
||
18 | protected $accountId; |
||
19 | |||
20 | /** |
||
21 | * @var string|null |
||
22 | * @JMS\Type("string") |
||
23 | * @JMS\SerializedName("Pricebook2Id") |
||
24 | * @JMS\Groups({"update", "create"}) |
||
25 | */ |
||
26 | protected $pricebookId; |
||
27 | |||
28 | /** |
||
29 | * @var string|null |
||
30 | * @JMS\Type("string") |
||
31 | * @JMS\Groups({"update", "create"}) |
||
32 | */ |
||
33 | protected $ownerExpirationNotice; |
||
34 | |||
35 | /** |
||
36 | * @var \DateTimeInterface|null |
||
37 | * @JMS\Type("DateTime<'Y-m-d'>") |
||
38 | * @JMS\Groups({"update", "create"}) |
||
39 | */ |
||
40 | protected $startDate; |
||
41 | |||
42 | /** |
||
43 | * Read-only. Calculated end date of the contract. |
||
44 | * This value is calculated by adding the ContractTerm to the StartDate. |
||
45 | * |
||
46 | * @var \DateTimeInterface |
||
47 | * @JMS\Type("DateTime<'Y-m-d'>") |
||
48 | */ |
||
49 | protected $endDate; |
||
50 | |||
51 | /** |
||
52 | * @var int|null |
||
53 | * @JMS\Type("integer") |
||
54 | * @JMS\Groups({"update", "create"}) |
||
55 | */ |
||
56 | protected $contractTerm; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | * @JMS\Type("string") |
||
61 | * @JMS\Groups({"update", "create"}) |
||
62 | */ |
||
63 | protected $ownerId; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | * @JMS\Type("string") |
||
68 | * @JMS\Groups({"update", "create"}) |
||
69 | */ |
||
70 | protected $status; |
||
71 | |||
72 | /** |
||
73 | * @var string |
||
74 | * @JMS\Type("string") |
||
75 | */ |
||
76 | protected $statusCode; |
||
77 | |||
78 | /** |
||
79 | * @var string|null |
||
80 | * @JMS\Type("string") |
||
81 | * @JMS\Groups({"update", "create"}) |
||
82 | */ |
||
83 | protected $companySignedId; |
||
84 | |||
85 | /** |
||
86 | * @var \DateTimeInterface|null |
||
87 | * @JMS\Type("string") |
||
88 | * @JMS\Groups({"update", "create"}) |
||
89 | */ |
||
90 | protected $companySignedDate; |
||
91 | |||
92 | /** |
||
93 | * @var string|null |
||
94 | * @JMS\Type("string") |
||
95 | * @JMS\Groups({"update", "create"}) |
||
96 | */ |
||
97 | protected $customerSignedId; |
||
98 | |||
99 | /** |
||
100 | * @var string|null |
||
101 | * @JMS\Type("string") |
||
102 | * @JMS\Groups({"update", "create"}) |
||
103 | */ |
||
104 | protected $customerSignedTitle; |
||
105 | |||
106 | /** |
||
107 | * @var \DateTimeInterface|null |
||
108 | * @JMS\Type("DateTime<'Y-m-d'>") |
||
109 | */ |
||
110 | protected $customerSignedDate; |
||
111 | |||
112 | /** |
||
113 | * @var string |
||
114 | * @JMS\Type("string") |
||
115 | * @JMS\Groups({"update", "create"}) |
||
116 | */ |
||
117 | protected $specialTerms; |
||
118 | |||
119 | /** |
||
120 | * @var string |
||
121 | * @JMS\Type("string") |
||
122 | * @JMS\Groups({"update", "create"}) |
||
123 | */ |
||
124 | protected $activatedById; |
||
125 | |||
126 | /** |
||
127 | * @var \DateTimeInterface |
||
128 | * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") |
||
129 | */ |
||
130 | protected $activatedDate; |
||
131 | |||
132 | /** |
||
133 | * @var string|null |
||
134 | * @JMS\Type("string") |
||
135 | * @JMS\Groups({"update", "create"}) |
||
136 | */ |
||
137 | protected $description; |
||
138 | |||
139 | /** |
||
140 | * @var bool |
||
141 | * @JMS\Type("boolean") |
||
142 | */ |
||
143 | protected $isDeleted; |
||
144 | |||
145 | /** |
||
146 | * @var string|null |
||
147 | * @JMS\Type("string") |
||
148 | */ |
||
149 | protected $contractNumber; |
||
150 | |||
151 | /** |
||
152 | * @var \DateTimeInterface|null |
||
153 | * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") |
||
154 | */ |
||
155 | protected $lastApprovedDate; |
||
156 | |||
157 | /** |
||
158 | * @var \DateTimeInterface|null |
||
159 | * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") |
||
160 | */ |
||
161 | protected $lastActivityDate; |
||
162 | |||
163 | /** |
||
164 | * @var \DateTimeInterface|null |
||
165 | * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") |
||
166 | */ |
||
167 | protected $lastViewedDate; |
||
168 | |||
169 | /** |
||
170 | * @var \DateTimeInterface|null |
||
171 | * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") |
||
172 | */ |
||
173 | protected $lastReferencedDate; |
||
174 | |||
175 | /** |
||
176 | * {@inheritdoc} |
||
177 | */ |
||
178 | public static function getSObjectName(): AbstractSObjectType |
||
182 | |||
183 | /** |
||
184 | * @return string|null |
||
185 | */ |
||
186 | public function getAccountId() |
||
190 | |||
191 | /** |
||
192 | * @return string|null |
||
193 | */ |
||
194 | public function getPricebookId() |
||
198 | |||
199 | /** |
||
200 | * @return string|null |
||
201 | */ |
||
202 | public function getOwnerExpirationNotice() |
||
206 | |||
207 | /** |
||
208 | * @return \DateTimeInterface|null |
||
209 | */ |
||
210 | public function getStartDate() |
||
214 | |||
215 | /** |
||
216 | * @return \DateTimeInterface|null |
||
217 | */ |
||
218 | public function getEndDate() |
||
222 | |||
223 | /** |
||
224 | * @return int|null |
||
225 | */ |
||
226 | public function getContractTerm() |
||
230 | |||
231 | /** |
||
232 | * @return string|null |
||
233 | */ |
||
234 | public function getOwnerId() |
||
238 | |||
239 | /** |
||
240 | * @return string|null |
||
241 | */ |
||
242 | public function getStatus() |
||
246 | |||
247 | /** |
||
248 | * @return string|null |
||
249 | */ |
||
250 | public function getStatusCode() |
||
254 | |||
255 | /** |
||
256 | * @return string|null |
||
257 | */ |
||
258 | public function getCompanySignedId() |
||
262 | |||
263 | /** |
||
264 | * @return \DateTimeInterface|null |
||
265 | */ |
||
266 | public function getCompanySignedDate() |
||
270 | |||
271 | /** |
||
272 | * @return string|null |
||
273 | */ |
||
274 | public function getCustomerSignedId() |
||
278 | |||
279 | /** |
||
280 | * @return string|null |
||
281 | */ |
||
282 | public function getCustomerSignedTitle() |
||
286 | |||
287 | /** |
||
288 | * @return \DateTimeInterface|null |
||
289 | */ |
||
290 | public function getCustomerSignedDate() |
||
294 | |||
295 | /** |
||
296 | * @return string|null |
||
297 | */ |
||
298 | public function getSpecialTerms() |
||
302 | |||
303 | /** |
||
304 | * @return string|null |
||
305 | */ |
||
306 | public function getActivatedById() |
||
310 | |||
311 | /** |
||
312 | * @return \DateTimeInterface|null |
||
313 | */ |
||
314 | public function getActivatedDate() |
||
318 | |||
319 | /** |
||
320 | * @return string|null |
||
321 | */ |
||
322 | public function getDescription() |
||
326 | |||
327 | /** |
||
328 | * @return bool|null |
||
329 | */ |
||
330 | public function isDeleted() |
||
334 | |||
335 | /** |
||
336 | * @return string|null |
||
337 | */ |
||
338 | public function getContractNumber() |
||
342 | |||
343 | /** |
||
344 | * @return \DateTimeInterface|null |
||
345 | */ |
||
346 | public function getLastApprovedDate() |
||
350 | |||
351 | /** |
||
352 | * @return \DateTimeInterface|null |
||
353 | */ |
||
354 | public function getLastActivityDate() |
||
358 | |||
359 | /** |
||
360 | * @return \DateTimeInterface|null |
||
361 | */ |
||
362 | public function getLastViewedDate() |
||
366 | |||
367 | /** |
||
368 | * @return \DateTimeInterface|null |
||
369 | */ |
||
370 | public function getLastReferencedDate() |
||
374 | |||
375 | public function setAccountId(string $accountId): self |
||
381 | |||
382 | public function setPricebookId(string $pricebookId = null): self |
||
388 | |||
389 | public function setOwnerExpirationNotice(string $ownerExpirationNotice = null): self |
||
395 | |||
396 | public function setStartDate(\DateTimeInterface $startDate = null): self |
||
402 | |||
403 | public function setContractTerm(int $contractTerm = null): self |
||
409 | |||
410 | public function setOwnerId(string $ownerId): self |
||
416 | |||
417 | public function setStatus(string $status): self |
||
423 | |||
424 | public function setCompanySignedId(string $companySignedId = null): self |
||
430 | |||
431 | public function setCompanySignedDate(\DateTimeInterface $companySignedDate = null): self |
||
437 | |||
438 | public function setCustomerSignedId(string $customerSignedId = null): self |
||
444 | |||
445 | public function setCustomerSignedTitle(string $customerSignedTitle = null): self |
||
451 | |||
452 | public function setCustomerSignedDate(\DateTimeInterface $customerSignedDate = null): self |
||
458 | |||
459 | public function setSpecialTerms(string $specialTerms): self |
||
465 | |||
466 | public function setActivatedById(string $activatedById): self |
||
472 | |||
473 | public function setActivatedDate(\DateTimeInterface $activatedDate): self |
||
479 | |||
480 | public function setDescription(string $description): self |
||
486 | |||
487 | public function setLastApprovedDate(\DateTimeInterface $lastApprovedDate): self |
||
493 | |||
494 | public function setLastActivityDate(\DateTimeInterface $lastActivityDate): self |
||
500 | |||
501 | public function setLastViewedDate(\DateTimeInterface $lastViewedDate): self |
||
507 | |||
508 | public function setLastReferencedDate(\DateTimeInterface $lastReferencedDate): self |
||
514 | } |
||
515 |