| Total Complexity | 44 |
| Total Lines | 527 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Opportunity 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 Opportunity, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class Opportunity extends AbstractSObject |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string|null |
||
| 13 | * @JMS\Type("string") |
||
| 14 | * @JMS\Groups({"create", "update"}) |
||
| 15 | */ |
||
| 16 | protected $accountId; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var float|null |
||
| 20 | * @JMS\Type("float") |
||
| 21 | * @JMS\Groups({"create", "update"}) |
||
| 22 | */ |
||
| 23 | protected $amount; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string|null |
||
| 27 | * @JMS\Type("string") |
||
| 28 | * @JMS\Groups({"create", "update"}) |
||
| 29 | */ |
||
| 30 | protected $campaignId; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var \DateTimeInterface |
||
| 34 | * @JMS\Type("DateTime<'Y-m-d'>") |
||
| 35 | * @JMS\Groups({"create", "update"}) |
||
| 36 | */ |
||
| 37 | protected $closeDate; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string|null |
||
| 41 | * @JMS\Type("string") |
||
| 42 | * @JMS\Groups({"create", "update"}) |
||
| 43 | */ |
||
| 44 | protected $description; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var float|null |
||
| 48 | * @JMS\Type("float") |
||
| 49 | */ |
||
| 50 | protected $expectedRevenue; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string|null |
||
| 54 | * @JMS\Type("string") |
||
| 55 | */ |
||
| 56 | protected $fiscal; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string|null |
||
| 60 | * @JMS\Type("string") |
||
| 61 | */ |
||
| 62 | protected $fiscalQuarter; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var int|null |
||
| 66 | * @JMS\Type("int") |
||
| 67 | */ |
||
| 68 | protected $fiscalYear; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var string|null |
||
| 72 | * @JMS\Type("string") |
||
| 73 | */ |
||
| 74 | protected $forecastCategory; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var string|null |
||
| 78 | * @JMS\Type("string") |
||
| 79 | * @JMS\Groups({"create", "update"}) |
||
| 80 | */ |
||
| 81 | protected $forecastCategoryName; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var bool |
||
| 85 | * @JMS\Type("boolean") |
||
| 86 | */ |
||
| 87 | protected $hasOpenActivity; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var bool |
||
| 91 | * @JMS\Type("boolean") |
||
| 92 | */ |
||
| 93 | protected $hasOpportunityLineItem; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var bool |
||
| 97 | * @JMS\Type("boolean") |
||
| 98 | */ |
||
| 99 | protected $hasOverdueTask; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var bool |
||
| 103 | * @JMS\Type("boolean") |
||
| 104 | */ |
||
| 105 | protected $isClosed; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var bool |
||
| 109 | * @JMS\Type("boolean") |
||
| 110 | */ |
||
| 111 | protected $isDeleted; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var bool |
||
| 115 | * @JMS\Type("boolean") |
||
| 116 | */ |
||
| 117 | protected $isWon; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var \DateTimeInterface|null |
||
| 121 | * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") |
||
| 122 | */ |
||
| 123 | protected $lastActivityDate; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @var \DateTimeInterface|null |
||
| 127 | * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") |
||
| 128 | */ |
||
| 129 | protected $lastReferencedDate; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @var \DateTimeInterface|null |
||
| 133 | * @JMS\Type("DateTime<'Y-m-d\TH:i:s.\0\0\0O'>") |
||
| 134 | */ |
||
| 135 | protected $lastViewedDate; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var string|null |
||
| 139 | * @JMS\Type("string") |
||
| 140 | * @JMS\Groups({"create", "update"}) |
||
| 141 | */ |
||
| 142 | protected $leadSource; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @var string |
||
| 146 | * @JMS\Type("string") |
||
| 147 | * @JMS\Groups({"create", "update"}) |
||
| 148 | */ |
||
| 149 | protected $name; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @var string|null |
||
| 153 | * @JMS\Type("string") |
||
| 154 | * @JMS\Groups({"create", "update"}) |
||
| 155 | */ |
||
| 156 | protected $nextStep; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var string |
||
| 160 | * @JMS\Type("string") |
||
| 161 | * @JMS\Groups({"create", "update"}) |
||
| 162 | */ |
||
| 163 | protected $ownerId; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @var string|null |
||
| 167 | * @JMS\Type("string") |
||
| 168 | * @JMS\Groups({"create", "update"}) |
||
| 169 | * @JMS\SerializedName("Pricebook2Id") |
||
| 170 | */ |
||
| 171 | protected $pricebookId; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var float|null |
||
| 175 | * @JMS\Type("float") |
||
| 176 | * @JMS\Groups({"create", "update"}) |
||
| 177 | */ |
||
| 178 | protected $probability; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @var string |
||
| 182 | * @JMS\Type("string") |
||
| 183 | * @JMS\Groups({"create", "update"}) |
||
| 184 | */ |
||
| 185 | protected $stageName; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @var float|null |
||
| 189 | * @JMS\Type("float") |
||
| 190 | * @JMS\Groups({"create", "update"}) |
||
| 191 | */ |
||
| 192 | protected $totalOpportunityQuantity; |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @var string|null |
||
| 196 | * @JMS\Type("string") |
||
| 197 | * @JMS\Groups({"create", "update"}) |
||
| 198 | */ |
||
| 199 | protected $type; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * {@inheritdoc} |
||
| 203 | */ |
||
| 204 | public static function getSObjectName(): AbstractSObjectType |
||
| 205 | { |
||
| 206 | return SObjectType::OPPORTUNITY(); |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @return string|null |
||
| 211 | */ |
||
| 212 | public function getAccountId() |
||
| 213 | { |
||
| 214 | return $this->accountId; |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @return float|null |
||
| 219 | */ |
||
| 220 | public function getAmount() |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @return string|null |
||
| 227 | */ |
||
| 228 | public function getCampaignId() |
||
| 229 | { |
||
| 230 | return $this->campaignId; |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return \DateTimeInterface |
||
| 235 | */ |
||
| 236 | public function getCloseDate() |
||
| 237 | { |
||
| 238 | return $this->closeDate; |
||
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @return string|null |
||
| 243 | */ |
||
| 244 | public function getDescription() |
||
| 245 | { |
||
| 246 | return $this->description; |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @return float|null |
||
| 251 | */ |
||
| 252 | public function getExpectedRevenue() |
||
| 253 | { |
||
| 254 | return $this->expectedRevenue; |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @return string|null |
||
| 259 | */ |
||
| 260 | public function getFiscal() |
||
| 261 | { |
||
| 262 | return $this->fiscal; |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @return string|null |
||
| 267 | */ |
||
| 268 | public function getFiscalQuarter() |
||
| 269 | { |
||
| 270 | return $this->fiscalQuarter; |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @return int|null |
||
| 275 | */ |
||
| 276 | public function getFiscalYear() |
||
| 277 | { |
||
| 278 | return $this->fiscalYear; |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @return string|null |
||
| 283 | */ |
||
| 284 | public function getForecastCategory() |
||
| 285 | { |
||
| 286 | return $this->forecastCategory; |
||
| 287 | } |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @return string|null |
||
| 291 | */ |
||
| 292 | public function getForecastCategoryName() |
||
| 293 | { |
||
| 294 | return $this->forecastCategoryName; |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @return bool|null |
||
| 299 | */ |
||
| 300 | public function hasOpenActivity() |
||
| 301 | { |
||
| 302 | return $this->hasOpenActivity; |
||
| 303 | } |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @return bool|null |
||
| 307 | */ |
||
| 308 | public function hasOpportunityLineItem() |
||
| 309 | { |
||
| 310 | return $this->hasOpportunityLineItem; |
||
| 311 | } |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @return bool|null |
||
| 315 | */ |
||
| 316 | public function hasOverdueTask() |
||
| 317 | { |
||
| 318 | return $this->hasOverdueTask; |
||
| 319 | } |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @return bool|null |
||
| 323 | */ |
||
| 324 | public function isClosed() |
||
| 325 | { |
||
| 326 | return $this->isClosed; |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @return bool|null |
||
| 331 | */ |
||
| 332 | public function isDeleted() |
||
| 333 | { |
||
| 334 | return $this->isDeleted; |
||
| 335 | } |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @return bool|null |
||
| 339 | */ |
||
| 340 | public function isWon() |
||
| 341 | { |
||
| 342 | return $this->isWon; |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @return \DateTimeInterface|null |
||
| 347 | */ |
||
| 348 | public function getLastReferencedDate() |
||
| 349 | { |
||
| 350 | return $this->lastReferencedDate; |
||
| 351 | } |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @return \DateTimeInterface|null |
||
| 355 | */ |
||
| 356 | public function getLastViewedDate() |
||
| 357 | { |
||
| 358 | return $this->lastViewedDate; |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @return string|null |
||
| 363 | */ |
||
| 364 | public function getLeadSource() |
||
| 365 | { |
||
| 366 | return $this->leadSource; |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @return string|null |
||
| 371 | */ |
||
| 372 | public function getName() |
||
| 373 | { |
||
| 374 | return $this->name; |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @return string|null |
||
| 379 | */ |
||
| 380 | public function getNextStep() |
||
| 381 | { |
||
| 382 | return $this->nextStep; |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @return string|null |
||
| 387 | */ |
||
| 388 | public function getOwnerId() |
||
| 389 | { |
||
| 390 | return $this->ownerId; |
||
| 391 | } |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @return string|null |
||
| 395 | */ |
||
| 396 | public function getPricebookId() |
||
| 397 | { |
||
| 398 | return $this->pricebookId; |
||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @return float|null |
||
| 403 | */ |
||
| 404 | public function getProbability() |
||
| 405 | { |
||
| 406 | return $this->probability; |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @return string|null |
||
| 411 | */ |
||
| 412 | public function getStageName() |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @return float|null |
||
| 419 | */ |
||
| 420 | public function getTotalOpportunityQuantity() |
||
| 421 | { |
||
| 422 | return $this->totalOpportunityQuantity; |
||
| 423 | } |
||
| 424 | |||
| 425 | /** |
||
| 426 | * @return string|null |
||
| 427 | */ |
||
| 428 | public function getType() |
||
| 431 | } |
||
| 432 | |||
| 433 | public function setAccountId(string $accountId = null): self |
||
| 434 | { |
||
| 435 | $this->accountId = $accountId; |
||
| 436 | |||
| 437 | return $this; |
||
| 438 | } |
||
| 439 | |||
| 440 | public function setAmount(float $amount = null): self |
||
| 441 | { |
||
| 442 | $this->amount = $amount; |
||
| 443 | |||
| 444 | return $this; |
||
| 445 | } |
||
| 446 | |||
| 447 | public function setCampaignId(string $campaignId = null): self |
||
| 448 | { |
||
| 449 | $this->campaignId = $campaignId; |
||
| 450 | |||
| 451 | return $this; |
||
| 452 | } |
||
| 453 | |||
| 454 | public function setCloseDate(\DateTimeInterface $closeDate): self |
||
| 455 | { |
||
| 456 | $this->closeDate = $closeDate; |
||
| 457 | |||
| 458 | return $this; |
||
| 459 | } |
||
| 460 | |||
| 461 | public function setDescription(string $description = null): self |
||
| 462 | { |
||
| 463 | $this->description = $description; |
||
| 464 | |||
| 465 | return $this; |
||
| 466 | } |
||
| 467 | |||
| 468 | public function setForecastCategoryName(string $forecastCategoryName = null): self |
||
| 469 | { |
||
| 470 | $this->forecastCategoryName = $forecastCategoryName; |
||
| 471 | |||
| 472 | return $this; |
||
| 473 | } |
||
| 474 | |||
| 475 | public function setLeadSource(string $leadSource = null): self |
||
| 476 | { |
||
| 477 | $this->leadSource = $leadSource; |
||
| 478 | |||
| 479 | return $this; |
||
| 480 | } |
||
| 481 | |||
| 482 | public function setName(string $name): self |
||
| 483 | { |
||
| 484 | $this->name = $name; |
||
| 485 | |||
| 486 | return $this; |
||
| 487 | } |
||
| 488 | |||
| 489 | public function setNextStep(string $nextStep = null): self |
||
| 494 | } |
||
| 495 | |||
| 496 | public function setOwnerId(string $ownerId): self |
||
| 497 | { |
||
| 498 | $this->ownerId = $ownerId; |
||
| 499 | |||
| 500 | return $this; |
||
| 501 | } |
||
| 502 | |||
| 503 | public function setPricebookId(string $pricebookId = null): self |
||
| 504 | { |
||
| 505 | $this->pricebookId = $pricebookId; |
||
| 506 | |||
| 507 | return $this; |
||
| 508 | } |
||
| 509 | |||
| 510 | public function setProbability(float $probability = null): self |
||
| 511 | { |
||
| 512 | $this->probability = $probability; |
||
| 513 | |||
| 514 | return $this; |
||
| 515 | } |
||
| 516 | |||
| 517 | public function setStageName(string $stageName): self |
||
| 518 | { |
||
| 519 | $this->stageName = $stageName; |
||
| 520 | |||
| 521 | return $this; |
||
| 522 | } |
||
| 523 | |||
| 524 | public function setTotalOpportunityQuantity(float $totalOpportunityQuantity = null): self |
||
| 525 | { |
||
| 526 | $this->totalOpportunityQuantity = $totalOpportunityQuantity; |
||
| 527 | |||
| 528 | return $this; |
||
| 529 | } |
||
| 530 | |||
| 531 | public function setType(string $type = null): self |
||
| 536 | } |
||
| 537 | } |
||
| 538 |