Complex classes like Order 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 Order, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 9 | class Order extends AbstractSObject  | 
            ||
| 10 | { | 
            ||
| 11 | use BillingAddressTrait;  | 
            ||
| 12 | use ShippingAddressTrait;  | 
            ||
| 13 | |||
| 14 | /**  | 
            ||
| 15 | * @var string|null  | 
            ||
| 16 |      * @JMS\Type("string") | 
            ||
| 17 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 18 | */  | 
            ||
| 19 | protected $ownerId;  | 
            ||
| 20 | |||
| 21 | /**  | 
            ||
| 22 | * @var string|null  | 
            ||
| 23 |      * @JMS\Type("string") | 
            ||
| 24 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 25 | */  | 
            ||
| 26 | protected $contractId;  | 
            ||
| 27 | |||
| 28 | /**  | 
            ||
| 29 | * @var string|null  | 
            ||
| 30 |      * @JMS\Type("string") | 
            ||
| 31 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 32 | */  | 
            ||
| 33 | protected $accountId;  | 
            ||
| 34 | |||
| 35 | /**  | 
            ||
| 36 | * @var string|null  | 
            ||
| 37 |      * @JMS\Type("string") | 
            ||
| 38 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 39 |      * @JMS\SerializedName("Pricebook2Id") | 
            ||
| 40 | */  | 
            ||
| 41 | protected $pricebookId;  | 
            ||
| 42 | |||
| 43 | /**  | 
            ||
| 44 | * @var string|null  | 
            ||
| 45 |      * @JMS\Type("string") | 
            ||
| 46 |      * @JMS\Groups({"create"}) | 
            ||
| 47 | */  | 
            ||
| 48 | protected $originalOrderId;  | 
            ||
| 49 | |||
| 50 | /**  | 
            ||
| 51 | * @var \DateTimeInterface|null  | 
            ||
| 52 |      * @JMS\Type("DateTime<'Y-m-d'>") | 
            ||
| 53 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 54 | */  | 
            ||
| 55 | protected $effectiveDate;  | 
            ||
| 56 | |||
| 57 | /**  | 
            ||
| 58 | * @var \DateTimeInterface|null  | 
            ||
| 59 |      * @JMS\Type("DateTime<'Y-m-d'>") | 
            ||
| 60 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 61 | */  | 
            ||
| 62 | protected $endDate;  | 
            ||
| 63 | |||
| 64 | /**  | 
            ||
| 65 | * @var bool  | 
            ||
| 66 |      * @JMS\Type("boolean") | 
            ||
| 67 | */  | 
            ||
| 68 | protected $isReductionOrder;  | 
            ||
| 69 | |||
| 70 | /**  | 
            ||
| 71 | * @var string  | 
            ||
| 72 |      * @JMS\Type("string") | 
            ||
| 73 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 74 | */  | 
            ||
| 75 | protected $status;  | 
            ||
| 76 | |||
| 77 | /**  | 
            ||
| 78 | * @var string|null  | 
            ||
| 79 |      * @JMS\Type("string") | 
            ||
| 80 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 81 | */  | 
            ||
| 82 | protected $description;  | 
            ||
| 83 | |||
| 84 | /**  | 
            ||
| 85 | * @var string|null  | 
            ||
| 86 |      * @JMS\Type("string") | 
            ||
| 87 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 88 | */  | 
            ||
| 89 | protected $customerAuthorizedById;  | 
            ||
| 90 | |||
| 91 | /**  | 
            ||
| 92 | * @var \DateTimeInterface|null  | 
            ||
| 93 |      * @JMS\Type("DateTime<'Y-m-d'>") | 
            ||
| 94 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 95 | */  | 
            ||
| 96 | protected $customerAuthorizedDate;  | 
            ||
| 97 | |||
| 98 | /**  | 
            ||
| 99 | * @var string|null  | 
            ||
| 100 |      * @JMS\Type("string") | 
            ||
| 101 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 102 | */  | 
            ||
| 103 | protected $companyAuthorizedById;  | 
            ||
| 104 | |||
| 105 | /**  | 
            ||
| 106 | * @var \DateTimeInterface|null  | 
            ||
| 107 |      * @JMS\Type("DateTime<'Y-m-d'>") | 
            ||
| 108 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 109 | */  | 
            ||
| 110 | protected $companyAuthorizedDate;  | 
            ||
| 111 | |||
| 112 | /**  | 
            ||
| 113 | * @var string|null  | 
            ||
| 114 |      * @JMS\Type("string") | 
            ||
| 115 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 116 | */  | 
            ||
| 117 | protected $type;  | 
            ||
| 118 | |||
| 119 | /**  | 
            ||
| 120 | * @var string|null  | 
            ||
| 121 |      * @JMS\Type("string") | 
            ||
| 122 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 123 | */  | 
            ||
| 124 | protected $name;  | 
            ||
| 125 | |||
| 126 | /**  | 
            ||
| 127 | * @var \DateTimeInterface|null  | 
            ||
| 128 |      * @JMS\Type("DateTime<'Y-m-d'>") | 
            ||
| 129 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 130 | */  | 
            ||
| 131 | protected $poDate;  | 
            ||
| 132 | |||
| 133 | /**  | 
            ||
| 134 | * @var string|null  | 
            ||
| 135 |      * @JMS\Type("string") | 
            ||
| 136 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 137 | */  | 
            ||
| 138 | protected $poNumber;  | 
            ||
| 139 | |||
| 140 | /**  | 
            ||
| 141 | * @var string|null  | 
            ||
| 142 |      * @JMS\Type("string") | 
            ||
| 143 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 144 | */  | 
            ||
| 145 | protected $orderReferenceNumber;  | 
            ||
| 146 | |||
| 147 | /**  | 
            ||
| 148 | * @var string|null  | 
            ||
| 149 |      * @JMS\Type("string") | 
            ||
| 150 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 151 | */  | 
            ||
| 152 | protected $billToContactId;  | 
            ||
| 153 | |||
| 154 | /**  | 
            ||
| 155 | * @var string|null  | 
            ||
| 156 |      * @JMS\Type("string") | 
            ||
| 157 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 158 | */  | 
            ||
| 159 | protected $shipToContactId;  | 
            ||
| 160 | |||
| 161 | /**  | 
            ||
| 162 | * @var \DateTimeInterface|null  | 
            ||
| 163 |      * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") | 
            ||
| 164 | */  | 
            ||
| 165 | protected $activatedDate;  | 
            ||
| 166 | |||
| 167 | /**  | 
            ||
| 168 | * @var string|null  | 
            ||
| 169 |      * @JMS\Type("string") | 
            ||
| 170 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 171 | */  | 
            ||
| 172 | protected $activatedById;  | 
            ||
| 173 | |||
| 174 | /**  | 
            ||
| 175 | * @var string|null  | 
            ||
| 176 |      * @JMS\Type("string") | 
            ||
| 177 |      * @JMS\Groups({"update", "create"}) | 
            ||
| 178 | */  | 
            ||
| 179 | protected $statusCode;  | 
            ||
| 180 | |||
| 181 | /**  | 
            ||
| 182 | * @var string|null  | 
            ||
| 183 |      * @JMS\Type("string") | 
            ||
| 184 | */  | 
            ||
| 185 | protected $orderNumber;  | 
            ||
| 186 | |||
| 187 | /**  | 
            ||
| 188 | * @var float|null  | 
            ||
| 189 |      * @JMS\Type("float") | 
            ||
| 190 | */  | 
            ||
| 191 | protected $totalAmount;  | 
            ||
| 192 | |||
| 193 | /**  | 
            ||
| 194 | * @var \DateTimeInterface|null  | 
            ||
| 195 |      * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") | 
            ||
| 196 | */  | 
            ||
| 197 | protected $lastViewedDate;  | 
            ||
| 198 | |||
| 199 | /**  | 
            ||
| 200 | * @var \DateTimeInterface|null  | 
            ||
| 201 |      * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") | 
            ||
| 202 | */  | 
            ||
| 203 | protected $lastReferencedDate;  | 
            ||
| 204 | |||
| 205 | /**  | 
            ||
| 206 | * @var bool|null  | 
            ||
| 207 |      * @JMS\Type("boolean") | 
            ||
| 208 | */  | 
            ||
| 209 | protected $isDeleted;  | 
            ||
| 210 | |||
| 211 | /**  | 
            ||
| 212 |      * {@inheritdoc} | 
            ||
| 213 | */  | 
            ||
| 214 | public static function getSObjectName(): AbstractSObjectType  | 
            ||
| 218 | |||
| 219 | /**  | 
            ||
| 220 | * @return string|null  | 
            ||
| 221 | */  | 
            ||
| 222 | public function getOwnerId()  | 
            ||
| 226 | |||
| 227 | /**  | 
            ||
| 228 | * @return string|null  | 
            ||
| 229 | */  | 
            ||
| 230 | public function getContractId()  | 
            ||
| 234 | |||
| 235 | /**  | 
            ||
| 236 | * @return string|null  | 
            ||
| 237 | */  | 
            ||
| 238 | public function getAccountId()  | 
            ||
| 242 | |||
| 243 | /**  | 
            ||
| 244 | * @return string|null  | 
            ||
| 245 | */  | 
            ||
| 246 | public function getPricebookId()  | 
            ||
| 250 | |||
| 251 | /**  | 
            ||
| 252 | * @return string|null  | 
            ||
| 253 | */  | 
            ||
| 254 | public function getOriginalOrderId()  | 
            ||
| 258 | |||
| 259 | /**  | 
            ||
| 260 | * @return \DateTimeInterface|null  | 
            ||
| 261 | */  | 
            ||
| 262 | public function getEffectiveDate()  | 
            ||
| 266 | |||
| 267 | /**  | 
            ||
| 268 | * @return \DateTimeInterface|null  | 
            ||
| 269 | */  | 
            ||
| 270 | public function getEndDate()  | 
            ||
| 274 | |||
| 275 | /**  | 
            ||
| 276 | * @return bool  | 
            ||
| 277 | */  | 
            ||
| 278 | public function getIsReductionOrder()  | 
            ||
| 282 | |||
| 283 | /**  | 
            ||
| 284 | * @return string|null  | 
            ||
| 285 | */  | 
            ||
| 286 | public function getStatus()  | 
            ||
| 290 | |||
| 291 | /**  | 
            ||
| 292 | * @return string|null  | 
            ||
| 293 | */  | 
            ||
| 294 | public function getDescription()  | 
            ||
| 298 | |||
| 299 | /**  | 
            ||
| 300 | * @return string|null  | 
            ||
| 301 | */  | 
            ||
| 302 | public function getCustomerAuthorizedById()  | 
            ||
| 306 | |||
| 307 | /**  | 
            ||
| 308 | * @return \DateTimeInterface|null  | 
            ||
| 309 | */  | 
            ||
| 310 | public function getCustomerAuthorizedDate()  | 
            ||
| 314 | |||
| 315 | /**  | 
            ||
| 316 | * @return string|null  | 
            ||
| 317 | */  | 
            ||
| 318 | public function getCompanyAuthorizedById()  | 
            ||
| 322 | |||
| 323 | /**  | 
            ||
| 324 | * @return \DateTimeInterface|null  | 
            ||
| 325 | */  | 
            ||
| 326 | public function getCompanyAuthorizedDate()  | 
            ||
| 330 | |||
| 331 | /**  | 
            ||
| 332 | * @return string|null  | 
            ||
| 333 | */  | 
            ||
| 334 | public function getType()  | 
            ||
| 338 | |||
| 339 | /**  | 
            ||
| 340 | * @return string|null  | 
            ||
| 341 | */  | 
            ||
| 342 | public function getName()  | 
            ||
| 346 | |||
| 347 | /**  | 
            ||
| 348 | * @return \DateTimeInterface|null  | 
            ||
| 349 | */  | 
            ||
| 350 | public function getPoDate()  | 
            ||
| 354 | |||
| 355 | /**  | 
            ||
| 356 | * @return string|null  | 
            ||
| 357 | */  | 
            ||
| 358 | public function getPoNumber()  | 
            ||
| 362 | |||
| 363 | /**  | 
            ||
| 364 | * @return string|null  | 
            ||
| 365 | */  | 
            ||
| 366 | public function getOrderReferenceNumber()  | 
            ||
| 370 | |||
| 371 | /**  | 
            ||
| 372 | * @return string|null  | 
            ||
| 373 | */  | 
            ||
| 374 | public function getBillToContactId()  | 
            ||
| 378 | |||
| 379 | /**  | 
            ||
| 380 | * @return string|null  | 
            ||
| 381 | */  | 
            ||
| 382 | public function getShipToContactId()  | 
            ||
| 386 | |||
| 387 | /**  | 
            ||
| 388 | * @return \DateTimeInterface|null  | 
            ||
| 389 | */  | 
            ||
| 390 | public function getActivatedDate()  | 
            ||
| 394 | |||
| 395 | /**  | 
            ||
| 396 | * @return string|null  | 
            ||
| 397 | */  | 
            ||
| 398 | public function getActivatedById()  | 
            ||
| 402 | |||
| 403 | /**  | 
            ||
| 404 | * @return string|null  | 
            ||
| 405 | */  | 
            ||
| 406 | public function getStatusCode()  | 
            ||
| 410 | |||
| 411 | /**  | 
            ||
| 412 | * @return string|null  | 
            ||
| 413 | */  | 
            ||
| 414 | public function getOrderNumber()  | 
            ||
| 418 | |||
| 419 | /**  | 
            ||
| 420 | * @return float|null  | 
            ||
| 421 | */  | 
            ||
| 422 | public function getTotalAmount()  | 
            ||
| 426 | |||
| 427 | /**  | 
            ||
| 428 | * @return \DateTimeInterface|null  | 
            ||
| 429 | */  | 
            ||
| 430 | public function getLastViewedDate()  | 
            ||
| 434 | |||
| 435 | /**  | 
            ||
| 436 | * @return \DateTimeInterface|null  | 
            ||
| 437 | */  | 
            ||
| 438 | public function getLastReferencedDate()  | 
            ||
| 442 | |||
| 443 | /**  | 
            ||
| 444 | * @return bool|null  | 
            ||
| 445 | */  | 
            ||
| 446 | public function isDeleted()  | 
            ||
| 450 | |||
| 451 | public function setOwnerId(string $ownerId): self  | 
            ||
| 457 | |||
| 458 | public function setContractId(string $contractId = null): self  | 
            ||
| 464 | |||
| 465 | public function setAccountId(string $accountId = null): self  | 
            ||
| 471 | |||
| 472 | public function setPricebookId(string $pricebookId = null): self  | 
            ||
| 478 | |||
| 479 | public function setOriginalOrderId(string $originalOrderId = null): self  | 
            ||
| 485 | |||
| 486 | public function setEffectiveDate(\DateTimeInterface $effectiveDate): self  | 
            ||
| 492 | |||
| 493 | public function setEndDate(\DateTimeInterface $endDate): self  | 
            ||
| 499 | |||
| 500 | public function setStatus(string $status): self  | 
            ||
| 506 | |||
| 507 | public function setDescription(string $description = null): self  | 
            ||
| 513 | |||
| 514 | public function setCustomerAuthorizedById(string $customerAuthorizedById = null): self  | 
            ||
| 520 | |||
| 521 | public function setCustomerAuthorizedDate(\DateTimeInterface $customerAuthorizedDate = null): self  | 
            ||
| 527 | |||
| 528 | public function setCompanyAuthorizedById(string $companyAuthorizedById = null): self  | 
            ||
| 534 | |||
| 535 | public function setCompanyAuthorizedDate(\DateTimeInterface $companyAuthorizedDate = null): self  | 
            ||
| 541 | |||
| 542 | public function setType(string $type = null): self  | 
            ||
| 548 | |||
| 549 | public function setName(string $name = null): self  | 
            ||
| 555 | |||
| 556 | public function setPoDate(\DateTimeInterface $poDate = null): self  | 
            ||
| 562 | |||
| 563 | public function setPoNumber(string $poNumber = null): self  | 
            ||
| 569 | |||
| 570 | public function setOrderReferenceNumber(string $orderReferenceNumber = null): self  | 
            ||
| 576 | |||
| 577 | public function setBillToContactId(string $billToContactId = null): self  | 
            ||
| 583 | |||
| 584 | public function setShipToContactId(string $shipToContactId = null): self  | 
            ||
| 590 | |||
| 591 | public function setActivatedDate(\DateTimeInterface $activatedDate = null): self  | 
            ||
| 597 | |||
| 598 | public function setActivatedById(string $activatedById = null): self  | 
            ||
| 604 | |||
| 605 | public function setStatusCode(string $statusCode): self  | 
            ||
| 611 | }  | 
            ||
| 612 |