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 |
||
| 39 | abstract class AbstractProductSubject extends AbstractEavSubject implements EntitySubjectInterface |
||
| 40 | { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The available stores. |
||
| 44 | * |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | protected $stores = array(); |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The available store websites. |
||
| 51 | * |
||
| 52 | * @var array |
||
| 53 | */ |
||
| 54 | protected $storeWebsites = array(); |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The available EAV attributes, grouped by their attribute set and the attribute set name as keys. |
||
| 58 | * |
||
| 59 | * @var array |
||
| 60 | */ |
||
| 61 | protected $attributes = array(); |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The available tax classes. |
||
| 65 | * |
||
| 66 | * @var array |
||
| 67 | */ |
||
| 68 | protected $taxClasses = array(); |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The available categories. |
||
| 72 | * |
||
| 73 | * @var array |
||
| 74 | */ |
||
| 75 | protected $categories = array(); |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The available link types. |
||
| 79 | * |
||
| 80 | * @var array |
||
| 81 | */ |
||
| 82 | protected $linkTypes = array(); |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The ID of the product that has been created recently. |
||
| 86 | * |
||
| 87 | * @var string |
||
| 88 | */ |
||
| 89 | protected $lastEntityId; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * The SKU of the product that has been created recently. |
||
| 93 | * |
||
| 94 | * @var string |
||
| 95 | */ |
||
| 96 | protected $lastSku; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * The Magento 2 configuration. |
||
| 100 | * |
||
| 101 | * @var array |
||
| 102 | */ |
||
| 103 | protected $coreConfigData; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * The mapping for the SKUs to the created entity IDs. |
||
| 107 | * |
||
| 108 | * @var array |
||
| 109 | */ |
||
| 110 | protected $skuEntityIdMapping = array(); |
||
| 111 | |||
| 112 | /** |
||
| 113 | * The mapping for the SKUs to the store view codes. |
||
| 114 | * |
||
| 115 | * @var array |
||
| 116 | */ |
||
| 117 | protected $skuStoreViewCodeMapping = array(); |
||
| 118 | |||
| 119 | /** |
||
| 120 | * The array with the available image types and their label columns. |
||
| 121 | * |
||
| 122 | * @var array |
||
| 123 | */ |
||
| 124 | protected $imageTypes = array( |
||
| 125 | 'base_image' => 'base_image_label', |
||
| 126 | 'small_image' => 'small_image_label', |
||
| 127 | 'swatch_image' => 'swatch_image_label', |
||
| 128 | 'thumbnail_image' => 'thumbnail_image_label' |
||
| 129 | ); |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Mappings for attribute code => CSV column header. |
||
| 133 | * |
||
| 134 | * @var array |
||
| 135 | */ |
||
| 136 | protected $headerMappings = array( |
||
| 137 | 'product_online' => 'status', |
||
| 138 | 'tax_class_name' => 'tax_class_id', |
||
| 139 | 'bundle_price_type' => 'price_type', |
||
| 140 | 'bundle_sku_type' => 'sku_type', |
||
| 141 | 'bundle_price_view' => 'price_view', |
||
| 142 | 'bundle_weight_type' => 'weight_type', |
||
| 143 | 'base_image' => 'image', |
||
| 144 | 'base_image_label' => 'image_label', |
||
| 145 | 'thumbnail_image' => 'thumbnail', |
||
| 146 | 'thumbnail_image_label'=> 'thumbnail_label', |
||
| 147 | 'bundle_shipment_type' => 'shipment_type', |
||
| 148 | 'related_skus' => 'relation_skus', |
||
| 149 | 'related_position' => 'relation_position', |
||
| 150 | 'crosssell_skus' => 'cross_sell_skus', |
||
| 151 | 'crosssell_position' => 'cross_sell_position', |
||
| 152 | 'upsell_skus' => 'up_sell_skus', |
||
| 153 | 'upsell_position' => 'up_sell_position' |
||
| 154 | ); |
||
| 155 | |||
| 156 | /** |
||
| 157 | * The default mappings for the user defined attributes, based on the attributes frontend input type. |
||
| 158 | * |
||
| 159 | * @var array |
||
| 160 | */ |
||
| 161 | protected $defaultFrontendInputCallbackMappings = array( |
||
| 162 | FrontendInputTypes::SELECT => 'import_product.callback.select', |
||
| 163 | FrontendInputTypes::MULTISELECT => 'import_product.callback.multiselect', |
||
| 164 | FrontendInputTypes::BOOLEAN => 'import_product.callback.boolean' |
||
| 165 | ); |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Return's the default callback frontend input mappings for the user defined attributes. |
||
| 169 | * |
||
| 170 | * @return array The default frontend input callback mappings |
||
| 171 | */ |
||
| 172 | 18 | public function getDefaultFrontendInputCallbackMappings() |
|
| 176 | |||
| 177 | /** |
||
| 178 | * Return's the available link types. |
||
| 179 | * |
||
| 180 | * @return array The link types |
||
| 181 | */ |
||
| 182 | public function getLinkTypes() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Set's the SKU of the last imported product. |
||
| 189 | * |
||
| 190 | * @param string $lastSku The SKU |
||
| 191 | * |
||
| 192 | * @return void |
||
| 193 | */ |
||
| 194 | public function setLastSku($lastSku) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Return's the SKU of the last imported product. |
||
| 201 | * |
||
| 202 | * @return string|null The SKU |
||
| 203 | */ |
||
| 204 | public function getLastSku() |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Set's the ID of the product that has been created recently. |
||
| 211 | * |
||
| 212 | * @param string $lastEntityId The entity ID |
||
| 213 | * |
||
| 214 | * @return void |
||
| 215 | */ |
||
| 216 | public function setLastEntityId($lastEntityId) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Return's the ID of the product that has been created recently. |
||
| 223 | * |
||
| 224 | * @return string The entity Id |
||
| 225 | */ |
||
| 226 | public function getLastEntityId() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Queries whether or not the SKU has already been processed. |
||
| 233 | * |
||
| 234 | * @param string $sku The SKU to check been processed |
||
| 235 | * |
||
| 236 | * @return boolean TRUE if the SKU has been processed, else FALSE |
||
| 237 | */ |
||
| 238 | public function hasBeenProcessed($sku) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Add the passed SKU => entity ID mapping. |
||
| 245 | * |
||
| 246 | * @param string $sku The SKU |
||
| 247 | * |
||
| 248 | * @return void |
||
| 249 | */ |
||
| 250 | public function addSkuEntityIdMapping($sku) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Add the passed SKU => store view code mapping. |
||
| 257 | * |
||
| 258 | * @param string $sku The SKU |
||
| 259 | * @param string $storeViewCode The store view code |
||
| 260 | * |
||
| 261 | * @return void |
||
| 262 | */ |
||
| 263 | public function addSkuStoreViewCodeMapping($sku, $storeViewCode) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 270 | * |
||
| 271 | * @param string $serial The serial of the actual import |
||
| 272 | * |
||
| 273 | * @return void |
||
| 274 | */ |
||
| 275 | 18 | public function setUp($serial) |
|
| 293 | |||
| 294 | /** |
||
| 295 | * Clean up the global data after importing the bunch. |
||
| 296 | * |
||
| 297 | * @param string $serial The serial of the actual import |
||
| 298 | * |
||
| 299 | * @return void |
||
| 300 | */ |
||
| 301 | public function tearDown($serial) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Return's the available image types. |
||
| 323 | * |
||
| 324 | * @return array The array with the available image types |
||
| 325 | */ |
||
| 326 | public function getImageTypes() |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Return's the store ID of the actual row, or of the default store |
||
| 333 | * if no store view code is set in the CSV file. |
||
| 334 | * |
||
| 335 | * @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
||
| 336 | * |
||
| 337 | * @return integer The ID of the actual store |
||
| 338 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
| 339 | */ |
||
| 340 | public function getRowStoreId($default = null) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Return's the tax class ID for the passed tax class name. |
||
| 367 | * |
||
| 368 | * @param string $taxClassName The tax class name to return the ID for |
||
| 369 | * |
||
| 370 | * @return integer The tax class ID |
||
| 371 | * @throws \Exception Is thrown, if the tax class with the requested name is not available |
||
| 372 | */ |
||
| 373 | View Code Duplication | public function getTaxClassIdByTaxClassName($taxClassName) |
|
| 388 | |||
| 389 | /** |
||
| 390 | * Return's the store website for the passed code. |
||
| 391 | * |
||
| 392 | * @param string $code The code of the store website to return the ID for |
||
| 393 | * |
||
| 394 | * @return integer The store website ID |
||
| 395 | * @throws \Exception Is thrown, if the store website with the requested code is not available |
||
| 396 | */ |
||
| 397 | View Code Duplication | public function getStoreWebsiteIdByCode($code) |
|
| 412 | |||
| 413 | /** |
||
| 414 | * Return's the category with the passed path. |
||
| 415 | * |
||
| 416 | * @param string $path The path of the category to return |
||
| 417 | * |
||
| 418 | * @return array The category |
||
| 419 | * @throws \Exception Is thrown, if the requested category is not available |
||
| 420 | */ |
||
| 421 | public function getCategoryByPath($path) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Return's the category with the passed ID. |
||
| 439 | * |
||
| 440 | * @param integer $categoryId The ID of the category to return |
||
| 441 | * |
||
| 442 | * @return array The category data |
||
| 443 | * @throws \Exception Is thrown, if the category is not available |
||
| 444 | */ |
||
| 445 | public function getCategory($categoryId) |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Return's the root category for the actual view store. |
||
| 465 | * |
||
| 466 | * @return array The store's root category |
||
| 467 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
| 468 | */ |
||
| 469 | public function getRootCategory() |
||
| 490 | } |
||
| 491 |