Total Complexity | 45 |
Total Lines | 504 |
Duplicated Lines | 0 % |
Changes | 0 |
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.
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 |
||
179 | { |
||
180 | return SObjectType::CONTRACT(); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @return string|null |
||
185 | */ |
||
186 | public function getAccountId() |
||
187 | { |
||
188 | return $this->accountId; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @return string|null |
||
193 | */ |
||
194 | public function getPricebookId() |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @return string|null |
||
201 | */ |
||
202 | public function getOwnerExpirationNotice() |
||
203 | { |
||
204 | return $this->ownerExpirationNotice; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @return \DateTimeInterface|null |
||
209 | */ |
||
210 | public function getStartDate() |
||
211 | { |
||
212 | return $this->startDate; |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * @return \DateTimeInterface|null |
||
217 | */ |
||
218 | public function getEndDate() |
||
219 | { |
||
220 | return $this->endDate; |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * @return int|null |
||
225 | */ |
||
226 | public function getContractTerm() |
||
227 | { |
||
228 | return $this->contractTerm; |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * @return string|null |
||
233 | */ |
||
234 | public function getOwnerId() |
||
235 | { |
||
236 | return $this->ownerId; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * @return string|null |
||
241 | */ |
||
242 | public function getStatus() |
||
243 | { |
||
244 | return $this->status; |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * @return string|null |
||
249 | */ |
||
250 | public function getStatusCode() |
||
251 | { |
||
252 | return $this->statusCode; |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * @return string|null |
||
257 | */ |
||
258 | public function getCompanySignedId() |
||
259 | { |
||
260 | return $this->companySignedId; |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * @return \DateTimeInterface|null |
||
265 | */ |
||
266 | public function getCompanySignedDate() |
||
267 | { |
||
268 | return $this->companySignedDate; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * @return string|null |
||
273 | */ |
||
274 | public function getCustomerSignedId() |
||
275 | { |
||
276 | return $this->customerSignedId; |
||
277 | } |
||
278 | |||
279 | /** |
||
280 | * @return string|null |
||
281 | */ |
||
282 | public function getCustomerSignedTitle() |
||
283 | { |
||
284 | return $this->customerSignedTitle; |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * @return \DateTimeInterface|null |
||
289 | */ |
||
290 | public function getCustomerSignedDate() |
||
291 | { |
||
292 | return $this->customerSignedDate; |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * @return string|null |
||
297 | */ |
||
298 | public function getSpecialTerms() |
||
299 | { |
||
300 | return $this->specialTerms; |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * @return string|null |
||
305 | */ |
||
306 | public function getActivatedById() |
||
307 | { |
||
308 | return $this->activatedById; |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * @return \DateTimeInterface|null |
||
313 | */ |
||
314 | public function getActivatedDate() |
||
315 | { |
||
316 | return $this->activatedDate; |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * @return string|null |
||
321 | */ |
||
322 | public function getDescription() |
||
323 | { |
||
324 | return $this->description; |
||
325 | } |
||
326 | |||
327 | /** |
||
328 | * @return bool|null |
||
329 | */ |
||
330 | public function isDeleted() |
||
331 | { |
||
332 | return $this->isDeleted; |
||
333 | } |
||
334 | |||
335 | /** |
||
336 | * @return string|null |
||
337 | */ |
||
338 | public function getContractNumber() |
||
339 | { |
||
340 | return $this->contractNumber; |
||
341 | } |
||
342 | |||
343 | /** |
||
344 | * @return \DateTimeInterface|null |
||
345 | */ |
||
346 | public function getLastApprovedDate() |
||
347 | { |
||
348 | return $this->lastApprovedDate; |
||
349 | } |
||
350 | |||
351 | /** |
||
352 | * @return \DateTimeInterface|null |
||
353 | */ |
||
354 | public function getLastActivityDate() |
||
355 | { |
||
356 | return $this->lastActivityDate; |
||
357 | } |
||
358 | |||
359 | /** |
||
360 | * @return \DateTimeInterface|null |
||
361 | */ |
||
362 | public function getLastViewedDate() |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * @return \DateTimeInterface|null |
||
369 | */ |
||
370 | public function getLastReferencedDate() |
||
373 | } |
||
374 | |||
375 | public function setAccountId(string $accountId): self |
||
376 | { |
||
377 | $this->accountId = $accountId; |
||
378 | |||
379 | return $this; |
||
380 | } |
||
381 | |||
382 | public function setPricebookId(string $pricebookId = null): self |
||
383 | { |
||
384 | $this->pricebookId = $pricebookId; |
||
385 | |||
386 | return $this; |
||
387 | } |
||
388 | |||
389 | public function setOwnerExpirationNotice(string $ownerExpirationNotice = null): self |
||
390 | { |
||
391 | $this->ownerExpirationNotice = $ownerExpirationNotice; |
||
392 | |||
393 | return $this; |
||
394 | } |
||
395 | |||
396 | public function setStartDate(\DateTimeInterface $startDate = null): self |
||
397 | { |
||
398 | $this->startDate = $startDate; |
||
399 | |||
400 | return $this; |
||
401 | } |
||
402 | |||
403 | public function setContractTerm(int $contractTerm = null): self |
||
404 | { |
||
405 | $this->contractTerm = $contractTerm; |
||
406 | |||
407 | return $this; |
||
408 | } |
||
409 | |||
410 | public function setOwnerId(string $ownerId): self |
||
411 | { |
||
412 | $this->ownerId = $ownerId; |
||
413 | |||
414 | return $this; |
||
415 | } |
||
416 | |||
417 | public function setStatus(string $status): self |
||
418 | { |
||
419 | $this->status = $status; |
||
420 | |||
421 | return $this; |
||
422 | } |
||
423 | |||
424 | public function setCompanySignedId(string $companySignedId = null): self |
||
425 | { |
||
426 | $this->companySignedId = $companySignedId; |
||
427 | |||
428 | return $this; |
||
429 | } |
||
430 | |||
431 | public function setCompanySignedDate(\DateTimeInterface $companySignedDate = null): self |
||
432 | { |
||
433 | $this->companySignedDate = $companySignedDate; |
||
434 | |||
435 | return $this; |
||
436 | } |
||
437 | |||
438 | public function setCustomerSignedId(string $customerSignedId = null): self |
||
439 | { |
||
440 | $this->customerSignedId = $customerSignedId; |
||
441 | |||
442 | return $this; |
||
443 | } |
||
444 | |||
445 | public function setCustomerSignedTitle(string $customerSignedTitle = null): self |
||
446 | { |
||
447 | $this->customerSignedTitle = $customerSignedTitle; |
||
448 | |||
449 | return $this; |
||
450 | } |
||
451 | |||
452 | public function setCustomerSignedDate(\DateTimeInterface $customerSignedDate = null): self |
||
453 | { |
||
454 | $this->customerSignedDate = $customerSignedDate; |
||
455 | |||
456 | return $this; |
||
457 | } |
||
458 | |||
459 | public function setSpecialTerms(string $specialTerms): self |
||
460 | { |
||
461 | $this->specialTerms = $specialTerms; |
||
462 | |||
463 | return $this; |
||
464 | } |
||
465 | |||
466 | public function setActivatedById(string $activatedById): self |
||
467 | { |
||
468 | $this->activatedById = $activatedById; |
||
469 | |||
470 | return $this; |
||
471 | } |
||
472 | |||
473 | public function setActivatedDate(\DateTimeInterface $activatedDate): self |
||
478 | } |
||
479 | |||
480 | public function setDescription(string $description): self |
||
481 | { |
||
482 | $this->description = $description; |
||
483 | |||
484 | return $this; |
||
485 | } |
||
486 | |||
487 | public function setLastApprovedDate(\DateTimeInterface $lastApprovedDate): self |
||
488 | { |
||
489 | $this->lastApprovedDate = $lastApprovedDate; |
||
490 | |||
491 | return $this; |
||
492 | } |
||
493 | |||
494 | public function setLastActivityDate(\DateTimeInterface $lastActivityDate): self |
||
495 | { |
||
496 | $this->lastActivityDate = $lastActivityDate; |
||
497 | |||
498 | return $this; |
||
499 | } |
||
500 | |||
501 | public function setLastViewedDate(\DateTimeInterface $lastViewedDate): self |
||
502 | { |
||
503 | $this->lastViewedDate = $lastViewedDate; |
||
504 | |||
505 | return $this; |
||
506 | } |
||
507 | |||
508 | public function setLastReferencedDate(\DateTimeInterface $lastReferencedDate): self |
||
513 | } |
||
514 | } |
||
515 |