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 | |||
| 126 | /** |
||
| 127 | * Mappings for CSV column header => attribute code. |
||
| 128 | * |
||
| 129 | * @var array |
||
| 130 | */ |
||
| 131 | protected $headerMappings = array( |
||
| 132 | 'product_online' => 'status', |
||
| 133 | 'tax_class_name' => 'tax_class_id', |
||
| 134 | 'bundle_price_type' => 'price_type', |
||
| 135 | 'bundle_sku_type' => 'sku_type', |
||
| 136 | 'bundle_price_view' => 'price_view', |
||
| 137 | 'bundle_weight_type' => 'weight_type', |
||
| 138 | 'base_image' => 'image', |
||
| 139 | 'base_image_label' => 'image_label', |
||
| 140 | 'thumbnail_image' => 'thumbnail', |
||
| 141 | 'thumbnail_image_label'=> 'thumbnail_label', |
||
| 142 | 'bundle_shipment_type' => 'shipment_type', |
||
| 143 | 'related_skus' => 'relation_skus', |
||
| 144 | 'related_position' => 'relation_position', |
||
| 145 | 'crosssell_skus' => 'cross_sell_skus', |
||
| 146 | 'crosssell_position' => 'cross_sell_position', |
||
| 147 | 'upsell_skus' => 'up_sell_skus', |
||
| 148 | 'upsell_position' => 'up_sell_position', |
||
| 149 | 'msrp_price' => 'msrp' |
||
| 150 | ); |
||
| 151 | |||
| 152 | /** |
||
| 153 | * The default mappings for the user defined attributes, based on the attributes frontend input type. |
||
| 154 | * |
||
| 155 | * @var array |
||
| 156 | */ |
||
| 157 | protected $defaultFrontendInputCallbackMappings = array( |
||
| 158 | FrontendInputTypes::SELECT => 'import_product.callback.select', |
||
| 159 | FrontendInputTypes::MULTISELECT => 'import_product.callback.multiselect', |
||
| 160 | FrontendInputTypes::BOOLEAN => 'import_product.callback.boolean' |
||
| 161 | ); |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Return's the default callback frontend input mappings for the user defined attributes. |
||
| 165 | * |
||
| 166 | * @return array The default frontend input callback mappings |
||
| 167 | */ |
||
| 168 | public function getDefaultFrontendInputCallbackMappings() |
||
| 172 | |||
| 173 | 18 | /** |
|
| 174 | * Return's the available link types. |
||
| 175 | 18 | * |
|
| 176 | * @return array The link types |
||
| 177 | */ |
||
| 178 | public function getLinkTypes() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Set's the SKU of the last imported product. |
||
| 185 | * |
||
| 186 | * @param string $lastSku The SKU |
||
| 187 | * |
||
| 188 | * @return void |
||
| 189 | */ |
||
| 190 | public function setLastSku($lastSku) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Return's the SKU of the last imported product. |
||
| 197 | * |
||
| 198 | * @return string|null The SKU |
||
| 199 | */ |
||
| 200 | public function getLastSku() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Set's the ID of the product that has been created recently. |
||
| 207 | * |
||
| 208 | * @param string $lastEntityId The entity ID |
||
| 209 | * |
||
| 210 | * @return void |
||
| 211 | */ |
||
| 212 | public function setLastEntityId($lastEntityId) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Return's the ID of the product that has been created recently. |
||
| 219 | * |
||
| 220 | * @return string The entity Id |
||
| 221 | */ |
||
| 222 | public function getLastEntityId() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Queries whether or not the SKU has already been processed. |
||
| 229 | * |
||
| 230 | * @param string $sku The SKU to check been processed |
||
| 231 | * |
||
| 232 | * @return boolean TRUE if the SKU has been processed, else FALSE |
||
| 233 | */ |
||
| 234 | public function hasBeenProcessed($sku) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Queries whether or not the passed PK and store view code has already been processed. |
||
| 241 | * |
||
| 242 | * @param string $pk The PK to check been processed |
||
| 243 | * @param string $storeViewCode The store view code to check been processed |
||
| 244 | * |
||
| 245 | * @return boolean TRUE if the PK and store view code has been processed, else FALSE |
||
| 246 | */ |
||
| 247 | public function storeViewHasBeenProcessed($pk, $storeViewCode) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Add the passed SKU => entity ID mapping. |
||
| 254 | * |
||
| 255 | * @param string $sku The SKU |
||
| 256 | * |
||
| 257 | * @return void |
||
| 258 | */ |
||
| 259 | public function addSkuEntityIdMapping($sku) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Add the passed SKU => store view code mapping. |
||
| 266 | * |
||
| 267 | * @param string $sku The SKU |
||
| 268 | * @param string $storeViewCode The store view code |
||
| 269 | * |
||
| 270 | * @return void |
||
| 271 | */ |
||
| 272 | public function addSkuStoreViewCodeMapping($sku, $storeViewCode) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 279 | * |
||
| 280 | * @param string $serial The serial of the actual import |
||
| 281 | * |
||
| 282 | * @return void |
||
| 283 | */ |
||
| 284 | public function setUp($serial) |
||
| 323 | |||
| 324 | |||
| 325 | /** |
||
| 326 | * Clean up the global data after importing the bunch. |
||
| 327 | * |
||
| 328 | * @param string $serial The serial of the actual import |
||
| 329 | * |
||
| 330 | * @return void |
||
| 331 | */ |
||
| 332 | public function tearDown($serial) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Return's the available image types. |
||
| 354 | * |
||
| 355 | * @return array The array with the available image types |
||
| 356 | */ |
||
| 357 | public function getImageTypes() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Return's the store ID of the actual row, or of the default store |
||
| 364 | * if no store view code is set in the CSV file. |
||
| 365 | * |
||
| 366 | * @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
||
| 367 | * |
||
| 368 | * @return integer The ID of the actual store |
||
| 369 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
| 370 | */ |
||
| 371 | public function getRowStoreId($default = null) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Return's the tax class ID for the passed tax class name. |
||
| 398 | * |
||
| 399 | * @param string $taxClassName The tax class name to return the ID for |
||
| 400 | * |
||
| 401 | * @return integer The tax class ID |
||
| 402 | * @throws \Exception Is thrown, if the tax class with the requested name is not available |
||
| 403 | */ |
||
| 404 | View Code Duplication | public function getTaxClassIdByTaxClassName($taxClassName) |
|
| 419 | |||
| 420 | /** |
||
| 421 | * Return's the store website for the passed code. |
||
| 422 | * |
||
| 423 | * @param string $code The code of the store website to return the ID for |
||
| 424 | * |
||
| 425 | * @return integer The store website ID |
||
| 426 | * @throws \Exception Is thrown, if the store website with the requested code is not available |
||
| 427 | */ |
||
| 428 | View Code Duplication | public function getStoreWebsiteIdByCode($code) |
|
| 443 | |||
| 444 | /** |
||
| 445 | * Return's the category with the passed path. |
||
| 446 | * |
||
| 447 | * @param string $path The path of the category to return |
||
| 448 | * |
||
| 449 | * @return array The category |
||
| 450 | * @throws \Exception Is thrown, if the requested category is not available |
||
| 451 | */ |
||
| 452 | public function getCategoryByPath($path) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Return's the category with the passed ID. |
||
| 470 | * |
||
| 471 | * @param integer $categoryId The ID of the category to return |
||
| 472 | * |
||
| 473 | * @return array The category data |
||
| 474 | * @throws \Exception Is thrown, if the category is not available |
||
| 475 | */ |
||
| 476 | public function getCategory($categoryId) |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Return's the root category for the actual view store. |
||
| 496 | * |
||
| 497 | * @return array The store's root category |
||
| 498 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
| 499 | */ |
||
| 500 | public function getRootCategory() |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Returns an array with the codes of the store views related with the passed website code. |
||
| 524 | * |
||
| 525 | * @param string $websiteCode The code of the website to return the store view codes for |
||
| 526 | * |
||
| 527 | * @return array The array with the matching store view codes |
||
| 528 | */ |
||
| 529 | public function getStoreViewCodesByWebsiteCode($websiteCode) |
||
| 558 | } |
||
| 559 |