Complex classes like Attribute 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 Attribute, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class Attribute extends ModelEntity |
||
| 20 | { |
||
| 21 | const STATUS_INSERT = 'insert'; |
||
| 22 | const STATUS_UPDATE = 'update'; |
||
| 23 | const STATUS_SYNCED = 'synced'; |
||
| 24 | const STATUS_ERROR = 'error'; |
||
| 25 | const STATUS_ERROR_PRICE = 'error-price'; |
||
| 26 | const STATUS_DELETE = 'delete'; |
||
| 27 | const STATUS_INACTIVE = 'inactive'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var int |
||
| 31 | * @ORM\Id |
||
| 32 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
| 33 | * @ORM\Column(name="id", type="integer", nullable=false) |
||
| 34 | */ |
||
| 35 | protected $id; |
||
| 36 | |||
| 37 | |||
| 38 | /** |
||
| 39 | * @var int |
||
| 40 | * |
||
| 41 | * @ORM\Column(name="article_id", type="integer", nullable=true) |
||
| 42 | */ |
||
| 43 | protected $articleId; |
||
| 44 | |||
| 45 | |||
| 46 | /** |
||
| 47 | * @var int |
||
| 48 | * |
||
| 49 | * @ORM\Column(name="article_detail_id", type="integer", nullable=true) |
||
| 50 | */ |
||
| 51 | protected $articleDetailId; |
||
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | * |
||
| 57 | * @ORM\Column(name="shop_id", type="string", nullable=true) |
||
| 58 | */ |
||
| 59 | protected $shopId; |
||
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * @var string |
||
| 64 | * |
||
| 65 | * @ORM\Column(name="source_id", type="string", nullable=true) |
||
| 66 | */ |
||
| 67 | protected $sourceId; |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * @var string |
||
| 72 | * |
||
| 73 | * @ORM\Column(name="export_status", type="text", nullable=true) |
||
| 74 | */ |
||
| 75 | protected $exportStatus; |
||
| 76 | |||
| 77 | |||
| 78 | /** |
||
| 79 | * @var string |
||
| 80 | * |
||
| 81 | * @ORM\Column(name="export_message", type="text", nullable=true) |
||
| 82 | */ |
||
| 83 | protected $exportMessage; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var bool |
||
| 87 | * |
||
| 88 | * @ORM\Column(name="exported", type="boolean", nullable=true) |
||
| 89 | */ |
||
| 90 | protected $exported; |
||
| 91 | |||
| 92 | |||
| 93 | /** |
||
| 94 | * @var string |
||
| 95 | * |
||
| 96 | * @ORM\Column(name="category", type="text", nullable=true) |
||
| 97 | */ |
||
| 98 | protected $category; |
||
| 99 | |||
| 100 | |||
| 101 | /** |
||
| 102 | * @var float |
||
| 103 | * |
||
| 104 | * @ORM\Column(name="purchase_price", type="float", nullable=true) |
||
| 105 | */ |
||
| 106 | protected $purchasePrice; |
||
| 107 | |||
| 108 | |||
| 109 | /** |
||
| 110 | * @var int |
||
| 111 | * |
||
| 112 | * @ORM\Column(name="fixed_price", type="integer", nullable=true) |
||
| 113 | */ |
||
| 114 | protected $fixedPrice; |
||
| 115 | |||
| 116 | |||
| 117 | /** |
||
| 118 | * @var string |
||
| 119 | * |
||
| 120 | * @ORM\Column(name="update_price", type="string", nullable=true) |
||
| 121 | */ |
||
| 122 | protected $updatePrice; |
||
| 123 | |||
| 124 | |||
| 125 | /** |
||
| 126 | * @var string |
||
| 127 | * |
||
| 128 | * @ORM\Column(name="update_image", type="string", nullable=true) |
||
| 129 | */ |
||
| 130 | protected $updateImage; |
||
| 131 | |||
| 132 | |||
| 133 | /** |
||
| 134 | * @var string |
||
| 135 | * |
||
| 136 | * @ORM\Column(name="update_long_description", type="string", nullable=true) |
||
| 137 | */ |
||
| 138 | protected $updateLongDescription; |
||
| 139 | |||
| 140 | |||
| 141 | /** |
||
| 142 | * @var string |
||
| 143 | * |
||
| 144 | * @ORM\Column(name="update_short_description", type="string", nullable=true) |
||
| 145 | */ |
||
| 146 | protected $updateShortDescription; |
||
| 147 | |||
| 148 | |||
| 149 | /** |
||
| 150 | * @var string |
||
| 151 | * |
||
| 152 | * @ORM\Column(name="update_additional_description", type="string", nullable=true) |
||
| 153 | */ |
||
| 154 | protected $updateAdditionalDescription; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @var string |
||
| 158 | * |
||
| 159 | * @ORM\Column(name="update_name", type="string", nullable=true) |
||
| 160 | */ |
||
| 161 | protected $updateName; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var string |
||
| 165 | * |
||
| 166 | * @ORM\Column(name="update_main_image", type="string", nullable=true) |
||
| 167 | */ |
||
| 168 | protected $updateMainImage; |
||
| 169 | |||
| 170 | |||
| 171 | /** |
||
| 172 | * @var string |
||
| 173 | * |
||
| 174 | * @ORM\Column(name="last_update", type="text", nullable=true) |
||
| 175 | */ |
||
| 176 | protected $lastUpdate; |
||
| 177 | |||
| 178 | |||
| 179 | /** |
||
| 180 | * @var int |
||
| 181 | * |
||
| 182 | * @ORM\Column(name="last_update_flag", type="integer", nullable=true) |
||
| 183 | */ |
||
| 184 | protected $lastUpdateFlag; |
||
| 185 | |||
| 186 | |||
| 187 | /** |
||
| 188 | * @var \Shopware\Models\Article\Article |
||
| 189 | * |
||
| 190 | * @ORM\OneToOne(targetEntity="Shopware\Models\Article\Article") |
||
| 191 | * @ORM\JoinColumns({ |
||
| 192 | * @ORM\JoinColumn(name="article_id", referencedColumnName="id") |
||
| 193 | * }) |
||
| 194 | */ |
||
| 195 | protected $article; |
||
| 196 | |||
| 197 | |||
| 198 | /** |
||
| 199 | * @var \Shopware\Models\Article\Detail |
||
| 200 | * |
||
| 201 | * @ORM\OneToOne(targetEntity="Shopware\Models\Article\Detail") |
||
| 202 | * @ORM\JoinColumns({ |
||
| 203 | * @ORM\JoinColumn(name="article_detail_id", referencedColumnName="id") |
||
| 204 | * }) |
||
| 205 | */ |
||
| 206 | protected $articleDetail; |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @var int |
||
| 210 | * @ORM\Column(name="group_id", type="integer", nullable=true) |
||
| 211 | */ |
||
| 212 | protected $groupId; |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @var bool |
||
| 216 | * @ORM\Column(name="is_main_variant", type="boolean", nullable=true) |
||
| 217 | */ |
||
| 218 | protected $isMainVariant; |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @var string |
||
| 222 | * |
||
| 223 | * @ORM\Column(name="purchase_price_hash", type="string", nullable=false) |
||
| 224 | */ |
||
| 225 | protected $purchasePriceHash; |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @var int |
||
| 229 | * @ORM\Column(name="offer_valid_until", type="integer", nullable=false) |
||
| 230 | */ |
||
| 231 | protected $offerValidUntil; |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @var string |
||
| 235 | * @ORM\Column(name="stream", type="string", nullable=false) |
||
| 236 | */ |
||
| 237 | protected $stream; |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @var bool |
||
| 241 | * @ORM\Column(name="cron_update", type="boolean", nullable=true) |
||
| 242 | */ |
||
| 243 | protected $cronUpdate; |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Used to store change revision for fromShop products |
||
| 247 | * |
||
| 248 | * @var string |
||
| 249 | * @ORM\Column(name="revision", type="decimal", precision=20, scale=10, nullable=true) |
||
| 250 | */ |
||
| 251 | protected $revision; |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @param \Shopware\Models\Article\Article $article |
||
| 255 | */ |
||
| 256 | public function setArticle($article) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @return \Shopware\Models\Article\Article |
||
| 263 | */ |
||
| 264 | public function getArticle() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param \Shopware\Models\Article\Detail $articleDetail |
||
| 271 | */ |
||
| 272 | public function setArticleDetail($articleDetail) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @return \Shopware\Models\Article\Detail |
||
| 279 | */ |
||
| 280 | public function getArticleDetail() |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @return int |
||
| 287 | */ |
||
| 288 | public function getArticleDetailId() |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return int |
||
| 295 | */ |
||
| 296 | public function getArticleId() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @param array $categories |
||
| 303 | */ |
||
| 304 | public function setCategory($categories) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @return array |
||
| 314 | */ |
||
| 315 | public function getCategory() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @param string $exportMessage |
||
| 322 | */ |
||
| 323 | public function setExportMessage($exportMessage) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @return string |
||
| 330 | */ |
||
| 331 | public function getExportMessage() |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @param string $exportStatus |
||
| 338 | */ |
||
| 339 | public function setExportStatus($exportStatus) |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @return string |
||
| 346 | */ |
||
| 347 | public function getExportStatus() |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @return bool |
||
| 354 | */ |
||
| 355 | public function isExported() |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @param bool $exported |
||
| 362 | */ |
||
| 363 | public function setExported($exported) |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @param int $fixedPrice |
||
| 370 | */ |
||
| 371 | public function setFixedPrice($fixedPrice) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @return int |
||
| 378 | */ |
||
| 379 | public function getFixedPrice() |
||
| 383 | |||
| 384 | /** |
||
| 385 | * @return int |
||
| 386 | */ |
||
| 387 | public function getId() |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @param string $lastUpdate |
||
| 394 | */ |
||
| 395 | public function setLastUpdate($lastUpdate) |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @return string |
||
| 402 | */ |
||
| 403 | public function getLastUpdate() |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @param int $lastUpdateFlag |
||
| 410 | */ |
||
| 411 | public function setLastUpdateFlag($lastUpdateFlag) |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Helper to inverse a given flag |
||
| 418 | * |
||
| 419 | * @param $flagToFlip |
||
| 420 | */ |
||
| 421 | public function flipLastUpdateFlag($flagToFlip) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @return int |
||
| 428 | */ |
||
| 429 | public function getLastUpdateFlag() |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @param float $purchasePrice |
||
| 436 | */ |
||
| 437 | public function setPurchasePrice($purchasePrice) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @return float |
||
| 444 | */ |
||
| 445 | public function getPurchasePrice() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param string $shopId |
||
| 452 | */ |
||
| 453 | public function setShopId($shopId) |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @return string |
||
| 460 | */ |
||
| 461 | public function getShopId() |
||
| 465 | |||
| 466 | /** |
||
| 467 | * @param string $sourceId |
||
| 468 | */ |
||
| 469 | public function setSourceId($sourceId) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @return string |
||
| 476 | */ |
||
| 477 | public function getSourceId() |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @param string $updateImage |
||
| 484 | */ |
||
| 485 | public function setUpdateImage($updateImage) |
||
| 489 | |||
| 490 | /** |
||
| 491 | * @return string |
||
| 492 | */ |
||
| 493 | public function getUpdateImage() |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @param string $updateLongDescription |
||
| 500 | */ |
||
| 501 | public function setUpdateLongDescription($updateLongDescription) |
||
| 505 | |||
| 506 | /** |
||
| 507 | * @return string |
||
| 508 | */ |
||
| 509 | public function getUpdateLongDescription() |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @return string |
||
| 516 | */ |
||
| 517 | public function getUpdateAdditionalDescription() |
||
| 521 | |||
| 522 | /** |
||
| 523 | * @param string $updateAdditionalDescription |
||
| 524 | */ |
||
| 525 | public function setUpdateAdditionalDescription($updateAdditionalDescription) |
||
| 529 | |||
| 530 | /** |
||
| 531 | * @param string $updateName |
||
| 532 | */ |
||
| 533 | public function setUpdateName($updateName) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @return string |
||
| 540 | */ |
||
| 541 | public function getUpdateName() |
||
| 545 | |||
| 546 | /** |
||
| 547 | * @param string $updatePrice |
||
| 548 | */ |
||
| 549 | public function setUpdatePrice($updatePrice) |
||
| 553 | |||
| 554 | /** |
||
| 555 | * @return string |
||
| 556 | */ |
||
| 557 | public function getUpdatePrice() |
||
| 561 | |||
| 562 | /** |
||
| 563 | * @param string $updateShortDescription |
||
| 564 | */ |
||
| 565 | public function setUpdateShortDescription($updateShortDescription) |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @return string |
||
| 572 | */ |
||
| 573 | public function getUpdateShortDescription() |
||
| 577 | |||
| 578 | /** |
||
| 579 | * @param string $updateMainImage |
||
| 580 | */ |
||
| 581 | public function setUpdateMainImage($updateMainImage) |
||
| 585 | |||
| 586 | /** |
||
| 587 | * @return string |
||
| 588 | */ |
||
| 589 | public function getUpdateMainImage() |
||
| 593 | |||
| 594 | /** |
||
| 595 | * @return mixed |
||
| 596 | */ |
||
| 597 | public function getGroupId() |
||
| 601 | |||
| 602 | /** |
||
| 603 | * @param mixed $groupId |
||
| 604 | */ |
||
| 605 | public function setGroupId($groupId) |
||
| 609 | |||
| 610 | /** |
||
| 611 | * @return bool |
||
| 612 | */ |
||
| 613 | public function isIsMainVariant() |
||
| 617 | |||
| 618 | /** |
||
| 619 | * @param bool $isMainVariant |
||
| 620 | */ |
||
| 621 | public function setIsMainVariant($isMainVariant) |
||
| 625 | |||
| 626 | /** |
||
| 627 | * @return int |
||
| 628 | */ |
||
| 629 | public function getOfferValidUntil() |
||
| 633 | |||
| 634 | /** |
||
| 635 | * @param int $offerValidUntil |
||
| 636 | */ |
||
| 637 | public function setOfferValidUntil($offerValidUntil) |
||
| 641 | |||
| 642 | /** |
||
| 643 | * @return string |
||
| 644 | */ |
||
| 645 | public function getPurchasePriceHash() |
||
| 649 | |||
| 650 | /** |
||
| 651 | * @param string $purchasePriceHash |
||
| 652 | */ |
||
| 653 | public function setPurchasePriceHash($purchasePriceHash) |
||
| 657 | |||
| 658 | /** |
||
| 659 | * @return string |
||
| 660 | */ |
||
| 661 | public function getStream() |
||
| 665 | |||
| 666 | /** |
||
| 667 | * @param string $stream |
||
| 668 | */ |
||
| 669 | public function setStream($stream) |
||
| 673 | |||
| 674 | /** |
||
| 675 | * @return bool |
||
| 676 | */ |
||
| 677 | public function isCronUpdate() |
||
| 681 | |||
| 682 | /** |
||
| 683 | * @param bool $cronUpdate |
||
| 684 | */ |
||
| 685 | public function setCronUpdate($cronUpdate) |
||
| 689 | |||
| 690 | /** |
||
| 691 | * @return string |
||
| 692 | */ |
||
| 693 | public function getRevision() |
||
| 697 | |||
| 698 | /** |
||
| 699 | * @param string $revision |
||
| 700 | */ |
||
| 701 | public function setRevision($revision) |
||
| 705 | } |
||
| 706 |