Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 38 | class BunchSubject extends AbstractProductSubject implements ExportableSubjectInterface |
||
|
|
|||
| 39 | { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The trait that implements the export functionality. |
||
| 43 | * |
||
| 44 | * @var \TechDivision\Import\Subjects\ExportableTrait |
||
| 45 | */ |
||
| 46 | use ExportableTrait; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The array with the pre-loaded entity IDs. |
||
| 50 | * |
||
| 51 | * @var array |
||
| 52 | */ |
||
| 53 | protected $preLoadedEntityIds = array(); |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Mappings for the table column => CSV column header. |
||
| 57 | * |
||
| 58 | * @var array |
||
| 59 | */ |
||
| 60 | protected $headerStockMappings = array( |
||
| 61 | 'qty' => array('qty', 'float'), |
||
| 62 | 'min_qty' => array('out_of_stock_qty', 'float'), |
||
| 63 | 'use_config_min_qty' => array('use_config_min_qty', 'int'), |
||
| 64 | 'is_qty_decimal' => array('is_qty_decimal', 'int'), |
||
| 65 | 'backorders' => array('allow_backorders', 'int'), |
||
| 66 | 'use_config_backorders' => array('use_config_backorders', 'int'), |
||
| 67 | 'min_sale_qty' => array('min_cart_qty', 'float'), |
||
| 68 | 'use_config_min_sale_qty' => array('use_config_min_sale_qty', 'int'), |
||
| 69 | 'max_sale_qty' => array('max_cart_qty', 'float'), |
||
| 70 | 'use_config_max_sale_qty' => array('use_config_max_sale_qty', 'int'), |
||
| 71 | 'is_in_stock' => array('is_in_stock', 'int'), |
||
| 72 | 'notify_stock_qty' => array('notify_on_stock_below', 'float'), |
||
| 73 | 'use_config_notify_stock_qty' => array('use_config_notify_stock_qty', 'int'), |
||
| 74 | 'manage_stock' => array('manage_stock', 'int'), |
||
| 75 | 'use_config_manage_stock' => array('use_config_manage_stock', 'int'), |
||
| 76 | 'use_config_qty_increments' => array('use_config_qty_increments', 'int'), |
||
| 77 | 'qty_increments' => array('qty_increments', 'float'), |
||
| 78 | 'use_config_enable_qty_inc' => array('use_config_enable_qty_inc', 'int'), |
||
| 79 | 'enable_qty_increments' => array('enable_qty_increments', 'int'), |
||
| 80 | 'is_decimal_divided' => array('is_decimal_divided', 'int'), |
||
| 81 | ); |
||
| 82 | |||
| 83 | /** |
||
| 84 | * The array with the available visibility keys. |
||
| 85 | * |
||
| 86 | * @var array |
||
| 87 | */ |
||
| 88 | protected $availableVisibilities = array( |
||
| 89 | 'Not Visible Individually' => VisibilityKeys::VISIBILITY_NOT_VISIBLE, |
||
| 90 | 'Catalog' => VisibilityKeys::VISIBILITY_IN_CATALOG, |
||
| 91 | 'Search' => VisibilityKeys::VISIBILITY_IN_SEARCH, |
||
| 92 | 'Catalog, Search' => VisibilityKeys::VISIBILITY_BOTH |
||
| 93 | ); |
||
| 94 | |||
| 95 | /** |
||
| 96 | * The category IDs the product is related with. |
||
| 97 | * |
||
| 98 | * @var array |
||
| 99 | */ |
||
| 100 | protected $productCategoryIds = array(); |
||
| 101 | |||
| 102 | /** |
||
| 103 | * The default callback mappings for the Magento standard product attributes. |
||
| 104 | * |
||
| 105 | * @var array |
||
| 106 | */ |
||
| 107 | protected $defaultCallbackMappings = array( |
||
| 108 | 'visibility' => array('import_product.callback.visibility'), |
||
| 109 | 'tax_class_id' => array('import_product.callback.tax.class'), |
||
| 110 | 'bundle_price_type' => array('import_product_bundle.callback.bundle.type'), |
||
| 111 | 'bundle_sku_type' => array('import_product_bundle.callback.bundle.type'), |
||
| 112 | 'bundle_weight_type' => array('import_product_bundle.callback.bundle.type'), |
||
| 113 | 'bundle_price_view' => array('import_product_bundle.callback.bundle.price.view'), |
||
| 114 | 'bundle_shipment_type' => array('import_product_bundle.callback.bundle.shipment.type') |
||
| 115 | ); |
||
| 116 | |||
| 117 | /** |
||
| 118 | * The used URL keys. |
||
| 119 | * |
||
| 120 | * @var array |
||
| 121 | */ |
||
| 122 | protected $usedUrlKeys = array(); |
||
| 123 | |||
| 124 | /** |
||
| 125 | * The available entity types. |
||
| 126 | * |
||
| 127 | * @var array |
||
| 128 | */ |
||
| 129 | protected $entityTypes = array(); |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 133 | * |
||
| 134 | * @param string $serial The serial of the actual import |
||
| 135 | * |
||
| 136 | * @return void |
||
| 137 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 138 | */ |
||
| 139 | public function setUp($serial) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Clean up the global data after importing the bunch. |
||
| 154 | * |
||
| 155 | * @param string $serial The serial of the actual import |
||
| 156 | * |
||
| 157 | * @return void |
||
| 158 | */ |
||
| 159 | public function tearDown($serial) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Return's the default callback mappings. |
||
| 179 | * |
||
| 180 | * @return array The default callback mappings |
||
| 181 | */ |
||
| 182 | public function getDefaultCallbackMappings() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Return's the mappings for the table column => CSV column header. |
||
| 189 | * |
||
| 190 | * @return array The header stock mappings |
||
| 191 | */ |
||
| 192 | public function getHeaderStockMappings() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Return's the visibility key for the passed visibility string. |
||
| 199 | * |
||
| 200 | * @param string $visibility The visibility string to return the key for |
||
| 201 | * |
||
| 202 | * @return integer The requested visibility key |
||
| 203 | * @throws \Exception Is thrown, if the requested visibility is not available |
||
| 204 | */ |
||
| 205 | public function getVisibilityIdByValue($visibility) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Add the passed category ID to the product's category list. |
||
| 223 | * |
||
| 224 | * @param integer $categoryId The category ID to add |
||
| 225 | * |
||
| 226 | * @return void |
||
| 227 | */ |
||
| 228 | public function addProductCategoryId($categoryId) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Pre-load the entity ID for the passed product. |
||
| 235 | * |
||
| 236 | * @param array $product The product to be pre-loaded |
||
| 237 | * |
||
| 238 | * @return void |
||
| 239 | */ |
||
| 240 | public function preLoadEntityId(array $product) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Return's the list with category IDs the product is related with. |
||
| 247 | * |
||
| 248 | * @return array The product's category IDs |
||
| 249 | */ |
||
| 250 | public function getProductCategoryIds() |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Return's the entity type for the configured entity type code. |
||
| 267 | * |
||
| 268 | * @return array The requested entity type |
||
| 269 | * @throws \Exception Is thrown, if the requested entity type is not available |
||
| 270 | */ |
||
| 271 | View Code Duplication | public function getEntityType() |
|
| 286 | |||
| 287 | /** |
||
| 288 | * Return's TRUE, if the passed URL key varchar value IS related with the actual PK. |
||
| 289 | * |
||
| 290 | * @param array $productVarcharAttribute The varchar value to check |
||
| 291 | * |
||
| 292 | * @return boolean TRUE if the URL key is related, else FALSE |
||
| 293 | */ |
||
| 294 | public function isUrlKeyOf(array $productVarcharAttribute) |
||
| 298 | } |
||
| 299 |