Complex classes like BunchSubject 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 BunchSubject, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 38 | class BunchSubject extends AbstractProductSubject |
||
| 39 | { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The mapping for the supported backend types (for the product entity) => persist methods. |
||
| 43 | * |
||
| 44 | * @var array |
||
| 45 | */ |
||
| 46 | protected $backendTypes = array( |
||
| 47 | 'datetime' => array('persistProductDatetimeAttribute', 'loadProductDatetimeAttribute'), |
||
| 48 | 'decimal' => array('persistProductDecimalAttribute', 'loadProductDecimalAttribute'), |
||
| 49 | 'int' => array('persistProductIntAttribute', 'loadProductIntAttribute'), |
||
| 50 | 'text' => array('persistProductTextAttribute', 'loadProductTextAttribute'), |
||
| 51 | 'varchar' => array('persistProductVarcharAttribute', 'loadProductVarcharAttribute') |
||
| 52 | ); |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Mappings for attribute code => CSV column header. |
||
| 56 | * |
||
| 57 | * @var array |
||
| 58 | */ |
||
| 59 | protected $headerMappings = array( |
||
| 60 | 'status' => 'product_online', |
||
| 61 | 'tax_class_id' => 'tax_class_name', |
||
| 62 | 'price_type' => 'bundle_price_type', |
||
| 63 | 'sku_type' => 'bundle_sku_type', |
||
| 64 | 'price_view' => 'bundle_price_view', |
||
| 65 | 'weight_type' => 'bundle_weight_type', |
||
| 66 | 'image' => 'base_image', |
||
| 67 | 'image_label' => 'base_image_label', |
||
| 68 | 'thumbnail' => 'thumbnail_image', |
||
| 69 | 'thumbnail_label' => 'thumbnail_image_label', |
||
| 70 | 'shipment_type' => 'bundle_shipment_type' |
||
| 71 | ); |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Mappings for the table column => CSV column header. |
||
| 75 | * |
||
| 76 | * @var array |
||
| 77 | */ |
||
| 78 | protected $headerStockMappings = array( |
||
| 79 | 'qty' => array('qty', 'float'), |
||
| 80 | 'min_qty' => array('out_of_stock_qty', 'float'), |
||
| 81 | 'use_config_min_qty' => array('use_config_min_qty', 'int'), |
||
| 82 | 'is_qty_decimal' => array('is_qty_decimal', 'int'), |
||
| 83 | 'backorders' => array('allow_backorders', 'int'), |
||
| 84 | 'use_config_backorders' => array('use_config_backorders', 'int'), |
||
| 85 | 'min_sale_qty' => array('min_cart_qty', 'float'), |
||
| 86 | 'use_config_min_sale_qty' => array('use_config_min_sale_qty', 'int'), |
||
| 87 | 'max_sale_qty' => array('max_cart_qty', 'float'), |
||
| 88 | 'use_config_max_sale_qty' => array('use_config_max_sale_qty', 'int'), |
||
| 89 | 'is_in_stock' => array('is_in_stock', 'int'), |
||
| 90 | 'notify_stock_qty' => array('notify_on_stock_below', 'float'), |
||
| 91 | 'use_config_notify_stock_qty' => array('use_config_notify_stock_qty', 'int'), |
||
| 92 | 'manage_stock' => array('manage_stock', 'int'), |
||
| 93 | 'use_config_manage_stock' => array('use_config_manage_stock', 'int'), |
||
| 94 | 'use_config_qty_increments' => array('use_config_qty_increments', 'int'), |
||
| 95 | 'qty_increments' => array('qty_increments', 'float'), |
||
| 96 | 'use_config_enable_qty_inc' => array('use_config_enable_qty_inc', 'int'), |
||
| 97 | 'enable_qty_increments' => array('enable_qty_increments', 'int'), |
||
| 98 | 'is_decimal_divided' => array('is_decimal_divided', 'int'), |
||
| 99 | ); |
||
| 100 | |||
| 101 | /** |
||
| 102 | * The array with the available visibility keys. |
||
| 103 | * |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | protected $availableVisibilities = array( |
||
| 107 | 'Not Visible Individually' => VisibilityKeys::VISIBILITY_NOT_VISIBLE, |
||
| 108 | 'Catalog' => VisibilityKeys::VISIBILITY_IN_CATALOG, |
||
| 109 | 'Search' => VisibilityKeys::VISIBILITY_IN_SEARCH, |
||
| 110 | 'Catalog, Search' => VisibilityKeys::VISIBILITY_BOTH |
||
| 111 | ); |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The attribute set of the product that has to be created. |
||
| 115 | * |
||
| 116 | * @var array |
||
| 117 | */ |
||
| 118 | protected $attributeSet = array(); |
||
| 119 | |||
| 120 | /** |
||
| 121 | * The array containing the data for product type configuration (configurables, bundles, etc). |
||
| 122 | * |
||
| 123 | * @var array |
||
| 124 | */ |
||
| 125 | protected $artefacs = array(); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * The mapping for the SKUs to the created entity IDs. |
||
| 129 | * |
||
| 130 | * @var array |
||
| 131 | */ |
||
| 132 | protected $skuEntityIdMapping = array(); |
||
| 133 | |||
| 134 | /** |
||
| 135 | * The category IDs the product is related with. |
||
| 136 | * |
||
| 137 | * @var array |
||
| 138 | */ |
||
| 139 | protected $productCategoryIds = array(); |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Set's the attribute set of the product that has to be created. |
||
| 143 | * |
||
| 144 | * @param array $attributeSet The attribute set |
||
| 145 | * |
||
| 146 | * @return void |
||
| 147 | */ |
||
| 148 | 1 | public function setAttributeSet(array $attributeSet) |
|
| 152 | |||
| 153 | /** |
||
| 154 | * Return's the attribute set of the product that has to be created. |
||
| 155 | * |
||
| 156 | * @return array The attribute set |
||
| 157 | */ |
||
| 158 | public function getAttributeSet() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Clean up the global data after importing the bunch. |
||
| 165 | * |
||
| 166 | * @return void |
||
| 167 | */ |
||
| 168 | public function tearDown() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Export's the artefacts to CSV files. |
||
| 189 | * |
||
| 190 | * @return void |
||
| 191 | */ |
||
| 192 | protected function exportArtefacts() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Return's the target directory for the artefact export. |
||
| 229 | * |
||
| 230 | * @return string The target directory for the artefact export |
||
| 231 | */ |
||
| 232 | protected function getTargetDir() |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Initialize and return the exporter configuration. |
||
| 239 | * |
||
| 240 | * @return \Goodby\CSV\Export\Standard\ExporterConfig The exporter configuration |
||
| 241 | */ |
||
| 242 | protected function getExportConfig() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Cast's the passed value based on the backend type information. |
||
| 284 | 1 | * |
|
| 285 | * @param string $backendType The backend type to cast to |
||
| 286 | * @param mixed $value The value to be casted |
||
| 287 | * |
||
| 288 | * @return mixed The casted value |
||
| 289 | 1 | */ |
|
| 290 | 1 | public function castValueByBackendType($backendType, $value) |
|
| 311 | |||
| 312 | /** |
||
| 313 | * Return's the mappings for the table column => CSV column header. |
||
| 314 | * |
||
| 315 | * @return array The header stock mappings |
||
| 316 | */ |
||
| 317 | public function getHeaderStockMappings() |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Return's mapping for the supported backend types (for the product entity) => persist methods. |
||
| 324 | * |
||
| 325 | * @return array The mapping for the supported backend types |
||
| 326 | */ |
||
| 327 | public function getBackendTypes() |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Return's the artefacts for post-processing. |
||
| 334 | * |
||
| 335 | * @return array The artefacts |
||
| 336 | */ |
||
| 337 | public function getArtefacts() |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Return's the visibility key for the passed visibility string. |
||
| 344 | * |
||
| 345 | * @param string $visibility The visibility string to return the key for |
||
| 346 | * |
||
| 347 | * @return integer The requested visibility key |
||
| 348 | * @throws \Exception Is thrown, if the requested visibility is not available |
||
| 349 | */ |
||
| 350 | public function getVisibilityIdByValue($visibility) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Map the passed attribute code, if a header mapping exists and return the |
||
| 364 | * mapped mapping. |
||
| 365 | * |
||
| 366 | * @param string $attributeCode The attribute code to map |
||
| 367 | * |
||
| 368 | * @return string The mapped attribute code, or the original one |
||
| 369 | */ |
||
| 370 | public function mapAttributeCodeByHeaderMapping($attributeCode) |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Add the passed product type artefacts to the product with the |
||
| 384 | * last entity ID. |
||
| 385 | * |
||
| 386 | * @param string $type The artefact type, e. g. configurable |
||
| 387 | * @param array $artefacts The product type artefacts |
||
| 388 | * |
||
| 389 | * @return void |
||
| 390 | * @uses \TechDivision\Import\Product\Subjects\BunchSubject::getLastEntityId() |
||
| 391 | */ |
||
| 392 | public function addArtefacts($type, array $artefacts) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Add the passed SKU => entity ID mapping. |
||
| 406 | * |
||
| 407 | * @param string $sku The SKU |
||
| 408 | * |
||
| 409 | * @return void |
||
| 410 | * @uses \Import\Csv\Actions\ProductImportBunchAction::getLastEntityId() |
||
| 411 | */ |
||
| 412 | public function addSkuEntityIdMapping($sku) |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Add the passed category ID to the product's category list. |
||
| 419 | * |
||
| 420 | * @param integer $categoryId The category ID to add |
||
| 421 | * |
||
| 422 | * @return void |
||
| 423 | */ |
||
| 424 | public function addProductCategoryId($categoryId) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Return's the list with category IDs the product is related with. |
||
| 431 | * |
||
| 432 | * @return array The product's category IDs |
||
| 433 | */ |
||
| 434 | public function getProductCategoryIds() |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Return's the attribute option value with the passed value and store ID. |
||
| 451 | * |
||
| 452 | * @param mixed $value The option value |
||
| 453 | * @param integer $storeId The ID of the store |
||
| 454 | * |
||
| 455 | * @return array|boolean The attribute option value instance |
||
| 456 | */ |
||
| 457 | public function getEavAttributeOptionValueByOptionValueAndStoreId($value, $storeId) |
||
| 461 | |||
| 462 | 1 | /** |
|
| 463 | * Return's the URL rewrites for the passed URL entity type and ID. |
||
| 464 | * |
||
| 465 | * @param string $entityType The entity type to load the URL rewrites for |
||
| 466 | * @param integer $entityId The entity ID to laod the rewrites for |
||
| 467 | * |
||
| 468 | * @return array The URL rewrites |
||
| 469 | */ |
||
| 470 | public function getUrlRewritesByEntityTypeAndEntityId($entityType, $entityId) |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Load's and return's the product with the passed SKU. |
||
| 477 | * |
||
| 478 | * @param string $sku The SKU of the product to load |
||
| 479 | * |
||
| 480 | * @return array The product |
||
| 481 | */ |
||
| 482 | public function loadProduct($sku) |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Load's and return's the product website relation with the passed product and website ID. |
||
| 489 | * |
||
| 490 | * @param string $productId The product ID of the relation |
||
| 491 | * @param string $websiteId The website ID of the relation |
||
| 492 | * |
||
| 493 | * @return array The product website |
||
| 494 | */ |
||
| 495 | public function loadProductWebsite($productId, $websiteId) |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Return's the category product relation with the passed category/product ID. |
||
| 502 | * |
||
| 503 | * @param integer $categoryId The category ID of the category product relation to return |
||
| 504 | * @param integer $productId The product ID of the category product relation to return |
||
| 505 | * |
||
| 506 | * @return array The category product relation |
||
| 507 | */ |
||
| 508 | public function loadCategoryProduct($categoryId, $productId) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Load's and return's the stock status with the passed product/website/stock ID. |
||
| 515 | * |
||
| 516 | * @param integer $productId The product ID of the stock status to load |
||
| 517 | * @param integer $websiteId The website ID of the stock status to load |
||
| 518 | * @param integer $stockId The stock ID of the stock status to load |
||
| 519 | * |
||
| 520 | * @return array The stock status |
||
| 521 | */ |
||
| 522 | public function loadStockStatus($productId, $websiteId, $stockId) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Load's and return's the stock status with the passed product/website/stock ID. |
||
| 529 | * |
||
| 530 | * @param integer $productId The product ID of the stock item to load |
||
| 531 | * @param integer $websiteId The website ID of the stock item to load |
||
| 532 | * @param integer $stockId The stock ID of the stock item to load |
||
| 533 | * |
||
| 534 | * @return array The stock item |
||
| 535 | */ |
||
| 536 | public function loadStockItem($productId, $websiteId, $stockId) |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Load's and return's the datetime attribute with the passed entity/attribute/store ID. |
||
| 543 | * |
||
| 544 | * @param integer $entityId The entity ID of the attribute |
||
| 545 | * @param integer $attributeId The attribute ID of the attribute |
||
| 546 | * @param integer $storeId The store ID of the attribute |
||
| 547 | * |
||
| 548 | * @return array|null The datetime attribute |
||
| 549 | */ |
||
| 550 | public function loadProductDatetimeAttribute($entityId, $attributeId, $storeId) |
||
| 554 | |||
| 555 | /** |
||
| 556 | * Load's and return's the decimal attribute with the passed entity/attribute/store ID. |
||
| 557 | * |
||
| 558 | * @param integer $entityId The entity ID of the attribute |
||
| 559 | * @param integer $attributeId The attribute ID of the attribute |
||
| 560 | * @param integer $storeId The store ID of the attribute |
||
| 561 | * |
||
| 562 | * @return array|null The decimal attribute |
||
| 563 | */ |
||
| 564 | public function loadProductDecimalAttribute($entityId, $attributeId, $storeId) |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Load's and return's the integer attribute with the passed entity/attribute/store ID. |
||
| 571 | * |
||
| 572 | * @param integer $entityId The entity ID of the attribute |
||
| 573 | * @param integer $attributeId The attribute ID of the attribute |
||
| 574 | * @param integer $storeId The store ID of the attribute |
||
| 575 | * |
||
| 576 | * @return array|null The integer attribute |
||
| 577 | */ |
||
| 578 | public function loadProductIntAttribute($entityId, $attributeId, $storeId) |
||
| 582 | |||
| 583 | /** |
||
| 584 | * Load's and return's the text attribute with the passed entity/attribute/store ID. |
||
| 585 | * |
||
| 586 | * @param integer $entityId The entity ID of the attribute |
||
| 587 | * @param integer $attributeId The attribute ID of the attribute |
||
| 588 | * @param integer $storeId The store ID of the attribute |
||
| 589 | * |
||
| 590 | * @return array|null The text attribute |
||
| 591 | */ |
||
| 592 | public function loadProductTextAttribute($entityId, $attributeId, $storeId) |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Load's and return's the varchar attribute with the passed entity/attribute/store ID. |
||
| 599 | * |
||
| 600 | * @param integer $entityId The entity ID of the attribute |
||
| 601 | * @param integer $attributeId The attribute ID of the attribute |
||
| 602 | * @param integer $storeId The store ID of the attribute |
||
| 603 | * |
||
| 604 | * @return array|null The varchar attribute |
||
| 605 | */ |
||
| 606 | public function loadProductVarcharAttribute($entityId, $attributeId, $storeId) |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Persist's the passed product data and return's the ID. |
||
| 613 | * |
||
| 614 | * @param array $product The product data to persist |
||
| 615 | * |
||
| 616 | * @return string The ID of the persisted entity |
||
| 617 | */ |
||
| 618 | public function persistProduct($product) |
||
| 622 | |||
| 623 | /** |
||
| 624 | * Persist's the passed product varchar attribute. |
||
| 625 | * |
||
| 626 | * @param array $attribute The attribute to persist |
||
| 627 | * |
||
| 628 | * @return void |
||
| 629 | */ |
||
| 630 | public function persistProductVarcharAttribute($attribute) |
||
| 634 | |||
| 635 | /** |
||
| 636 | * Persist's the passed product integer attribute. |
||
| 637 | * |
||
| 638 | * @param array $attribute The attribute to persist |
||
| 639 | * |
||
| 640 | * @return void |
||
| 641 | */ |
||
| 642 | public function persistProductIntAttribute($attribute) |
||
| 646 | |||
| 647 | /** |
||
| 648 | * Persist's the passed product decimal attribute. |
||
| 649 | * |
||
| 650 | * @param array $attribute The attribute to persist |
||
| 651 | * |
||
| 652 | * @return void |
||
| 653 | */ |
||
| 654 | public function persistProductDecimalAttribute($attribute) |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Persist's the passed product datetime attribute. |
||
| 661 | * |
||
| 662 | * @param array $attribute The attribute to persist |
||
| 663 | * |
||
| 664 | * @return void |
||
| 665 | */ |
||
| 666 | public function persistProductDatetimeAttribute($attribute) |
||
| 670 | |||
| 671 | /** |
||
| 672 | * Persist's the passed product text attribute. |
||
| 673 | * |
||
| 674 | * @param array $attribute The attribute to persist |
||
| 675 | * |
||
| 676 | * @return void |
||
| 677 | */ |
||
| 678 | public function persistProductTextAttribute($attribute) |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Persist's the passed product website data and return's the ID. |
||
| 685 | * |
||
| 686 | * @param array $productWebsite The product website data to persist |
||
| 687 | * |
||
| 688 | * @return void |
||
| 689 | */ |
||
| 690 | public function persistProductWebsite($productWebsite) |
||
| 694 | |||
| 695 | /** |
||
| 696 | * Persist's the passed category product relation. |
||
| 697 | * |
||
| 698 | * @param array $categoryProduct The category product relation to persist |
||
| 699 | * |
||
| 700 | * @return void |
||
| 701 | */ |
||
| 702 | public function persistCategoryProduct($categoryProduct) |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Persist's the passed stock item data and return's the ID. |
||
| 709 | * |
||
| 710 | * @param array $stockItem The stock item data to persist |
||
| 711 | * |
||
| 712 | * @return void |
||
| 713 | */ |
||
| 714 | public function persistStockItem($stockItem) |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Persist's the passed stock status data and return's the ID. |
||
| 721 | * |
||
| 722 | * @param array $stockStatus The stock status data to persist |
||
| 723 | * |
||
| 724 | * @return void |
||
| 725 | */ |
||
| 726 | public function persistStockStatus($stockStatus) |
||
| 730 | 1 | ||
| 731 | 1 | /** |
|
| 732 | * Persist's the URL write with the passed data. |
||
| 733 | * |
||
| 734 | * @param array $row The URL rewrite to persist |
||
| 735 | * |
||
| 736 | * @return void |
||
| 737 | */ |
||
| 738 | public function persistUrlRewrite($row) |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Delete's the entity with the passed attributes. |
||
| 745 | * |
||
| 746 | * @param array $row The attributes of the entity to delete |
||
| 747 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 748 | * |
||
| 749 | * @return void |
||
| 750 | */ |
||
| 751 | public function deleteProduct($row, $name = null) |
||
| 755 | |||
| 756 | 1 | /** |
|
| 757 | 1 | * Delete's the URL rewrite(s) with the passed attributes. |
|
| 758 | * |
||
| 759 | * @param array $row The attributes of the entity to delete |
||
| 760 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 761 | * |
||
| 762 | * @return void |
||
| 763 | */ |
||
| 764 | public function deleteUrlRewrite($row, $name = null) |
||
| 768 | |||
| 769 | /** |
||
| 770 | * Delete's the stock item(s) with the passed attributes. |
||
| 771 | * |
||
| 772 | * @param array $row The attributes of the entity to delete |
||
| 773 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 774 | * |
||
| 775 | * @return void |
||
| 776 | */ |
||
| 777 | public function deleteStockItem($row, $name = null) |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Delete's the stock status with the passed attributes. |
||
| 784 | * |
||
| 785 | * @param array $row The attributes of the entity to delete |
||
| 786 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 787 | * |
||
| 788 | * @return void |
||
| 789 | */ |
||
| 790 | public function deleteStockStatus($row, $name = null) |
||
| 794 | |||
| 795 | /** |
||
| 796 | * Delete's the product website relations with the passed attributes. |
||
| 797 | * |
||
| 798 | * @param array $row The attributes of the entity to delete |
||
| 799 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 800 | * |
||
| 801 | * @return void |
||
| 802 | */ |
||
| 803 | public function deleteProductWebsite($row, $name = null) |
||
| 807 | |||
| 808 | /** |
||
| 809 | * Delete's the category product relations with the passed attributes. |
||
| 810 | * |
||
| 811 | * @param array $row The attributes of the entity to delete |
||
| 812 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 813 | * |
||
| 814 | * @return void |
||
| 815 | */ |
||
| 816 | public function deleteCategoryProduct($row, $name = null) |
||
| 820 | } |
||
| 821 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.