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() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Return's the target directory for the artefact export. |
||
| 227 | * |
||
| 228 | * @return string The target directory for the artefact export |
||
| 229 | */ |
||
| 230 | protected function getTargetDir() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Initialize and return the exporter configuration. |
||
| 237 | * |
||
| 238 | * @return \Goodby\CSV\Export\Standard\ExporterConfig The exporter configuration |
||
| 239 | */ |
||
| 240 | protected function getExportConfig() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Cast's the passed value based on the backend type information. |
||
| 282 | * |
||
| 283 | * @param string $backendType The backend type to cast to |
||
| 284 | * @param mixed $value The value to be casted |
||
| 285 | * |
||
| 286 | * @return mixed The casted value |
||
| 287 | */ |
||
| 288 | 1 | public function castValueByBackendType($backendType, $value) |
|
| 309 | |||
| 310 | /** |
||
| 311 | * Return's the mappings for the table column => CSV column header. |
||
| 312 | * |
||
| 313 | * @return array The header stock mappings |
||
| 314 | */ |
||
| 315 | 1 | public function getHeaderStockMappings() |
|
| 319 | |||
| 320 | /** |
||
| 321 | * Return's mapping for the supported backend types (for the product entity) => persist methods. |
||
| 322 | * |
||
| 323 | * @return array The mapping for the supported backend types |
||
| 324 | */ |
||
| 325 | public function getBackendTypes() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Return's the artefacts for post-processing. |
||
| 332 | * |
||
| 333 | * @return array The artefacts |
||
| 334 | */ |
||
| 335 | public function getArtefacts() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Return's the visibility key for the passed visibility string. |
||
| 342 | * |
||
| 343 | * @param string $visibility The visibility string to return the key for |
||
| 344 | * |
||
| 345 | * @return integer The requested visibility key |
||
| 346 | * @throws \Exception Is thrown, if the requested visibility is not available |
||
| 347 | */ |
||
| 348 | public function getVisibilityIdByValue($visibility) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Map the passed attribute code, if a header mapping exists and return the |
||
| 362 | * mapped mapping. |
||
| 363 | * |
||
| 364 | * @param string $attributeCode The attribute code to map |
||
| 365 | * |
||
| 366 | * @return string The mapped attribute code, or the original one |
||
| 367 | */ |
||
| 368 | public function mapAttributeCodeByHeaderMapping($attributeCode) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Add the passed product type artefacts to the product with the |
||
| 382 | * last entity ID. |
||
| 383 | * |
||
| 384 | * @param string $type The artefact type, e. g. configurable |
||
| 385 | * @param array $artefacts The product type artefacts |
||
| 386 | * |
||
| 387 | * @return void |
||
| 388 | * @uses \TechDivision\Import\Product\Subjects\BunchSubject::getLastEntityId() |
||
| 389 | */ |
||
| 390 | public function addArtefacts($type, array $artefacts) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Add the passed SKU => entity ID mapping. |
||
| 404 | * |
||
| 405 | * @param string $sku The SKU |
||
| 406 | * |
||
| 407 | * @return void |
||
| 408 | * @uses \Import\Csv\Actions\ProductImportBunchAction::getLastEntityId() |
||
| 409 | */ |
||
| 410 | public function addSkuEntityIdMapping($sku) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Add the passed category ID to the product's category list. |
||
| 417 | * |
||
| 418 | * @param integer $categoryId The category ID to add |
||
| 419 | * |
||
| 420 | * @return void |
||
| 421 | */ |
||
| 422 | public function addProductCategoryId($categoryId) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Return's the list with category IDs the product is related with. |
||
| 429 | * |
||
| 430 | * @return array The product's category IDs |
||
| 431 | */ |
||
| 432 | public function getProductCategoryIds() |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Return's the attribute option value with the passed value and store ID. |
||
| 449 | * |
||
| 450 | * @param mixed $value The option value |
||
| 451 | * @param integer $storeId The ID of the store |
||
| 452 | * |
||
| 453 | * @return array|boolean The attribute option value instance |
||
| 454 | */ |
||
| 455 | public function getEavAttributeOptionValueByOptionValueAndStoreId($value, $storeId) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Return's the URL rewrites for the passed URL entity type and ID. |
||
| 462 | * |
||
| 463 | * @param string $entityType The entity type to load the URL rewrites for |
||
| 464 | * @param integer $entityId The entity ID to laod the rewrites for |
||
| 465 | * |
||
| 466 | * @return array The URL rewrites |
||
| 467 | */ |
||
| 468 | 1 | public function getUrlRewritesByEntityTypeAndEntityId($entityType, $entityId) |
|
| 472 | |||
| 473 | /** |
||
| 474 | * Load's and return's the product with the passed SKU. |
||
| 475 | * |
||
| 476 | * @param string $sku The SKU of the product to load |
||
| 477 | * |
||
| 478 | * @return array The product |
||
| 479 | */ |
||
| 480 | public function loadProduct($sku) |
||
| 484 | |||
| 485 | /** |
||
| 486 | * Load's and return's the product website relation with the passed product and website ID. |
||
| 487 | * |
||
| 488 | * @param string $productId The product ID of the relation |
||
| 489 | * @param string $websiteId The website ID of the relation |
||
| 490 | * |
||
| 491 | * @return array The product website |
||
| 492 | */ |
||
| 493 | public function loadProductWebsite($productId, $websiteId) |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Return's the category product relation with the passed category/product ID. |
||
| 500 | * |
||
| 501 | * @param integer $categoryId The category ID of the category product relation to return |
||
| 502 | * @param integer $productId The product ID of the category product relation to return |
||
| 503 | * |
||
| 504 | * @return array The category product relation |
||
| 505 | */ |
||
| 506 | public function loadCategoryProduct($categoryId, $productId) |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Load's and return's the stock status with the passed product/website/stock ID. |
||
| 513 | * |
||
| 514 | * @param integer $productId The product ID of the stock status to load |
||
| 515 | * @param integer $websiteId The website ID of the stock status to load |
||
| 516 | * @param integer $stockId The stock ID of the stock status to load |
||
| 517 | * |
||
| 518 | * @return array The stock status |
||
| 519 | */ |
||
| 520 | public function loadStockStatus($productId, $websiteId, $stockId) |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Load's and return's the stock status with the passed product/website/stock ID. |
||
| 527 | * |
||
| 528 | * @param integer $productId The product ID of the stock item to load |
||
| 529 | * @param integer $websiteId The website ID of the stock item to load |
||
| 530 | * @param integer $stockId The stock ID of the stock item to load |
||
| 531 | * |
||
| 532 | * @return array The stock item |
||
| 533 | */ |
||
| 534 | public function loadStockItem($productId, $websiteId, $stockId) |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Load's and return's the datetime attribute with the passed entity/attribute/store ID. |
||
| 541 | * |
||
| 542 | * @param integer $entityId The entity ID of the attribute |
||
| 543 | * @param integer $attributeId The attribute ID of the attribute |
||
| 544 | * @param integer $storeId The store ID of the attribute |
||
| 545 | * |
||
| 546 | * @return array|null The datetime attribute |
||
| 547 | */ |
||
| 548 | public function loadProductDatetimeAttribute($entityId, $attributeId, $storeId) |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Load's and return's the decimal attribute with the passed entity/attribute/store ID. |
||
| 555 | * |
||
| 556 | * @param integer $entityId The entity ID of the attribute |
||
| 557 | * @param integer $attributeId The attribute ID of the attribute |
||
| 558 | * @param integer $storeId The store ID of the attribute |
||
| 559 | * |
||
| 560 | * @return array|null The decimal attribute |
||
| 561 | */ |
||
| 562 | public function loadProductDecimalAttribute($entityId, $attributeId, $storeId) |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Load's and return's the integer attribute with the passed entity/attribute/store ID. |
||
| 569 | * |
||
| 570 | * @param integer $entityId The entity ID of the attribute |
||
| 571 | * @param integer $attributeId The attribute ID of the attribute |
||
| 572 | * @param integer $storeId The store ID of the attribute |
||
| 573 | * |
||
| 574 | * @return array|null The integer attribute |
||
| 575 | */ |
||
| 576 | public function loadProductIntAttribute($entityId, $attributeId, $storeId) |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Load's and return's the text attribute with the passed entity/attribute/store ID. |
||
| 583 | * |
||
| 584 | * @param integer $entityId The entity ID of the attribute |
||
| 585 | * @param integer $attributeId The attribute ID of the attribute |
||
| 586 | * @param integer $storeId The store ID of the attribute |
||
| 587 | * |
||
| 588 | * @return array|null The text attribute |
||
| 589 | */ |
||
| 590 | public function loadProductTextAttribute($entityId, $attributeId, $storeId) |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Load's and return's the varchar attribute with the passed entity/attribute/store ID. |
||
| 597 | * |
||
| 598 | * @param integer $entityId The entity ID of the attribute |
||
| 599 | * @param integer $attributeId The attribute ID of the attribute |
||
| 600 | * @param integer $storeId The store ID of the attribute |
||
| 601 | * |
||
| 602 | * @return array|null The varchar attribute |
||
| 603 | */ |
||
| 604 | public function loadProductVarcharAttribute($entityId, $attributeId, $storeId) |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Persist's the passed product data and return's the ID. |
||
| 611 | * |
||
| 612 | * @param array $product The product data to persist |
||
| 613 | * |
||
| 614 | * @return string The ID of the persisted entity |
||
| 615 | */ |
||
| 616 | public function persistProduct($product) |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Persist's the passed product varchar attribute. |
||
| 623 | * |
||
| 624 | * @param array $attribute The attribute to persist |
||
| 625 | * |
||
| 626 | * @return void |
||
| 627 | */ |
||
| 628 | public function persistProductVarcharAttribute($attribute) |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Persist's the passed product integer attribute. |
||
| 635 | * |
||
| 636 | * @param array $attribute The attribute to persist |
||
| 637 | * |
||
| 638 | * @return void |
||
| 639 | */ |
||
| 640 | public function persistProductIntAttribute($attribute) |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Persist's the passed product decimal attribute. |
||
| 647 | * |
||
| 648 | * @param array $attribute The attribute to persist |
||
| 649 | * |
||
| 650 | * @return void |
||
| 651 | */ |
||
| 652 | public function persistProductDecimalAttribute($attribute) |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Persist's the passed product datetime attribute. |
||
| 659 | * |
||
| 660 | * @param array $attribute The attribute to persist |
||
| 661 | * |
||
| 662 | * @return void |
||
| 663 | */ |
||
| 664 | public function persistProductDatetimeAttribute($attribute) |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Persist's the passed product text attribute. |
||
| 671 | * |
||
| 672 | * @param array $attribute The attribute to persist |
||
| 673 | * |
||
| 674 | * @return void |
||
| 675 | */ |
||
| 676 | public function persistProductTextAttribute($attribute) |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Persist's the passed product website data and return's the ID. |
||
| 683 | * |
||
| 684 | * @param array $productWebsite The product website data to persist |
||
| 685 | * |
||
| 686 | * @return void |
||
| 687 | */ |
||
| 688 | public function persistProductWebsite($productWebsite) |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Persist's the passed category product relation. |
||
| 695 | * |
||
| 696 | * @param array $categoryProduct The category product relation to persist |
||
| 697 | * |
||
| 698 | * @return void |
||
| 699 | */ |
||
| 700 | public function persistCategoryProduct($categoryProduct) |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Persist's the passed stock item data and return's the ID. |
||
| 707 | * |
||
| 708 | * @param array $stockItem The stock item data to persist |
||
| 709 | * |
||
| 710 | * @return void |
||
| 711 | */ |
||
| 712 | public function persistStockItem($stockItem) |
||
| 716 | |||
| 717 | /** |
||
| 718 | * Persist's the passed stock status data and return's the ID. |
||
| 719 | * |
||
| 720 | * @param array $stockStatus The stock status data to persist |
||
| 721 | * |
||
| 722 | * @return void |
||
| 723 | */ |
||
| 724 | public function persistStockStatus($stockStatus) |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Persist's the URL write with the passed data. |
||
| 731 | * |
||
| 732 | * @param array $row The URL rewrite to persist |
||
| 733 | * |
||
| 734 | * @return void |
||
| 735 | */ |
||
| 736 | 1 | public function persistUrlRewrite($row) |
|
| 740 | |||
| 741 | /** |
||
| 742 | * Delete's the entity with the passed attributes. |
||
| 743 | * |
||
| 744 | * @param array $row The attributes of the entity to delete |
||
| 745 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 746 | * |
||
| 747 | * @return void |
||
| 748 | */ |
||
| 749 | public function deleteProduct($row, $name = null) |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Delete's the URL rewrite(s) with the passed attributes. |
||
| 756 | * |
||
| 757 | * @param array $row The attributes of the entity to delete |
||
| 758 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 759 | * |
||
| 760 | * @return void |
||
| 761 | */ |
||
| 762 | 1 | public function deleteUrlRewrite($row, $name = null) |
|
| 766 | |||
| 767 | /** |
||
| 768 | * Delete's the stock item(s) with the passed attributes. |
||
| 769 | * |
||
| 770 | * @param array $row The attributes of the entity to delete |
||
| 771 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 772 | * |
||
| 773 | * @return void |
||
| 774 | */ |
||
| 775 | public function deleteStockItem($row, $name = null) |
||
| 779 | |||
| 780 | /** |
||
| 781 | * Delete's the stock status with the passed attributes. |
||
| 782 | * |
||
| 783 | * @param array $row The attributes of the entity to delete |
||
| 784 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 785 | * |
||
| 786 | * @return void |
||
| 787 | */ |
||
| 788 | public function deleteStockStatus($row, $name = null) |
||
| 792 | |||
| 793 | /** |
||
| 794 | * Delete's the product website relations with the passed attributes. |
||
| 795 | * |
||
| 796 | * @param array $row The attributes of the entity to delete |
||
| 797 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 798 | * |
||
| 799 | * @return void |
||
| 800 | */ |
||
| 801 | public function deleteProductWebsite($row, $name = null) |
||
| 805 | |||
| 806 | /** |
||
| 807 | * Delete's the category product relations with the passed attributes. |
||
| 808 | * |
||
| 809 | * @param array $row The attributes of the entity to delete |
||
| 810 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 811 | * |
||
| 812 | * @return void |
||
| 813 | */ |
||
| 814 | public function deleteCategoryProduct($row, $name = null) |
||
| 818 | } |
||
| 819 |
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.