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 |
||
| 40 | abstract class AbstractProductSubject extends AbstractEavSubject implements EntitySubjectInterface |
||
| 41 | { |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The available stores. |
||
| 45 | * |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | protected $stores = array(); |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The available store websites. |
||
| 52 | * |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | protected $storeWebsites = array(); |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The available EAV attributes, grouped by their attribute set and the attribute set name as keys. |
||
| 59 | * |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | protected $attributes = array(); |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The available tax classes. |
||
| 66 | * |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | protected $taxClasses = array(); |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The available categories. |
||
| 73 | * |
||
| 74 | * @var array |
||
| 75 | */ |
||
| 76 | protected $categories = array(); |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The available link types. |
||
| 80 | * |
||
| 81 | * @var array |
||
| 82 | */ |
||
| 83 | protected $linkTypes = array(); |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The ID of the product that has been created recently. |
||
| 87 | * |
||
| 88 | * @var string |
||
| 89 | */ |
||
| 90 | protected $lastEntityId; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * The SKU of the product that has been created recently. |
||
| 94 | * |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | protected $lastSku; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * The Magento 2 configuration. |
||
| 101 | * |
||
| 102 | * @var array |
||
| 103 | */ |
||
| 104 | protected $coreConfigData; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * The mapping for the SKUs to the created entity IDs. |
||
| 108 | * |
||
| 109 | * @var array |
||
| 110 | */ |
||
| 111 | protected $skuEntityIdMapping = array(); |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The mapping for the SKUs to the store view codes. |
||
| 115 | * |
||
| 116 | * @var array |
||
| 117 | */ |
||
| 118 | protected $skuStoreViewCodeMapping = array(); |
||
| 119 | |||
| 120 | /** |
||
| 121 | * The array with the available image types and their label columns. |
||
| 122 | * |
||
| 123 | * @var array |
||
| 124 | */ |
||
| 125 | protected $imageTypes = array(); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Mappings for CSV column header => attribute code. |
||
| 129 | * |
||
| 130 | * @var array |
||
| 131 | */ |
||
| 132 | protected $headerMappings = array( |
||
| 133 | 'product_online' => 'status', |
||
| 134 | 'tax_class_name' => 'tax_class_id', |
||
| 135 | 'bundle_price_type' => 'price_type', |
||
| 136 | 'bundle_sku_type' => 'sku_type', |
||
| 137 | 'bundle_price_view' => 'price_view', |
||
| 138 | 'bundle_weight_type' => 'weight_type', |
||
| 139 | 'bundle_shipment_type' => 'shipment_type', |
||
| 140 | 'related_skus' => 'relation_skus', |
||
| 141 | 'related_position' => 'relation_position', |
||
| 142 | 'crosssell_skus' => 'cross_sell_skus', |
||
| 143 | 'crosssell_position' => 'cross_sell_position', |
||
| 144 | 'upsell_skus' => 'up_sell_skus', |
||
| 145 | 'upsell_position' => 'up_sell_position', |
||
| 146 | 'msrp_price' => 'msrp', |
||
| 147 | 'base_image' => 'image', |
||
| 148 | 'base_image_label' => 'image_label', |
||
| 149 | 'thumbnail_image' => 'thumbnail', |
||
| 150 | 'thumbnail_image_label'=> 'thumbnail_label' |
||
| 151 | ); |
||
| 152 | |||
| 153 | /** |
||
| 154 | * The default mappings for the user defined attributes, based on the attributes frontend input type. |
||
| 155 | * |
||
| 156 | * @var array |
||
| 157 | */ |
||
| 158 | protected $defaultFrontendInputCallbackMappings = array( |
||
| 159 | FrontendInputTypes::SELECT => 'import_product.callback.select', |
||
| 160 | FrontendInputTypes::MULTISELECT => 'import_product.callback.multiselect', |
||
| 161 | FrontendInputTypes::BOOLEAN => 'import_product.callback.boolean' |
||
| 162 | ); |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Return's the default callback frontend input mappings for the user defined attributes. |
||
| 166 | * |
||
| 167 | * @return array The default frontend input callback mappings |
||
| 168 | */ |
||
| 169 | 18 | public function getDefaultFrontendInputCallbackMappings() |
|
| 170 | { |
||
| 171 | 18 | return $this->defaultFrontendInputCallbackMappings; |
|
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Return's the available link types. |
||
| 176 | * |
||
| 177 | * @return array The link types |
||
| 178 | */ |
||
| 179 | public function getLinkTypes() |
||
| 180 | { |
||
| 181 | return $this->linkTypes; |
||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Set's the SKU of the last imported product. |
||
| 186 | * |
||
| 187 | * @param string $lastSku The SKU |
||
| 188 | * |
||
| 189 | * @return void |
||
| 190 | */ |
||
| 191 | public function setLastSku($lastSku) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Return's the SKU of the last imported product. |
||
| 198 | * |
||
| 199 | * @return string|null The SKU |
||
| 200 | */ |
||
| 201 | public function getLastSku() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Set's the ID of the product that has been created recently. |
||
| 208 | * |
||
| 209 | * @param string $lastEntityId The entity ID |
||
| 210 | * |
||
| 211 | * @return void |
||
| 212 | */ |
||
| 213 | public function setLastEntityId($lastEntityId) |
||
| 214 | { |
||
| 215 | $this->lastEntityId = $lastEntityId; |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Return's the ID of the product that has been created recently. |
||
| 220 | * |
||
| 221 | * @return string The entity Id |
||
| 222 | */ |
||
| 223 | public function getLastEntityId() |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Queries whether or not the SKU has already been processed. |
||
| 230 | * |
||
| 231 | * @param string $sku The SKU to check been processed |
||
| 232 | * |
||
| 233 | * @return boolean TRUE if the SKU has been processed, else FALSE |
||
| 234 | */ |
||
| 235 | public function hasBeenProcessed($sku) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Queries whether or not the passed PK and store view code has already been processed. |
||
| 242 | * |
||
| 243 | * @param string $pk The PK to check been processed |
||
| 244 | * @param string $storeViewCode The store view code to check been processed |
||
| 245 | * |
||
| 246 | * @return boolean TRUE if the PK and store view code has been processed, else FALSE |
||
| 247 | */ |
||
| 248 | public function storeViewHasBeenProcessed($pk, $storeViewCode) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Add the passed SKU => entity ID mapping. |
||
| 255 | * |
||
| 256 | * @param string $sku The SKU |
||
| 257 | * |
||
| 258 | * @return void |
||
| 259 | */ |
||
| 260 | public function addSkuEntityIdMapping($sku) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Add the passed SKU => store view code mapping. |
||
| 267 | * |
||
| 268 | * @param string $sku The SKU |
||
| 269 | * @param string $storeViewCode The store view code |
||
| 270 | * |
||
| 271 | * @return void |
||
| 272 | */ |
||
| 273 | public function addSkuStoreViewCodeMapping($sku, $storeViewCode) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 280 | * |
||
| 281 | * @param string $serial The serial of the actual import |
||
| 282 | * |
||
| 283 | * @return void |
||
| 284 | */ |
||
| 285 | 18 | public function setUp($serial) |
|
| 301 | |||
| 302 | |||
| 303 | /** |
||
| 304 | * Clean up the global data after importing the bunch. |
||
| 305 | * |
||
| 306 | * @param string $serial The serial of the actual import |
||
| 307 | * |
||
| 308 | * @return void |
||
| 309 | */ |
||
| 310 | public function tearDown($serial) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Return's the available image types. |
||
| 332 | * |
||
| 333 | * @return array The array with the available image types |
||
| 334 | */ |
||
| 335 | public function getImageTypes() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Return's the store ID of the actual row, or of the default store |
||
| 342 | * if no store view code is set in the CSV file. |
||
| 343 | * |
||
| 344 | * @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
||
| 345 | * |
||
| 346 | * @return integer The ID of the actual store |
||
| 347 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
| 348 | */ |
||
| 349 | public function getRowStoreId($default = null) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Return's the tax class ID for the passed tax class name. |
||
| 376 | * |
||
| 377 | * @param string $taxClassName The tax class name to return the ID for |
||
| 378 | * |
||
| 379 | * @return integer The tax class ID |
||
| 380 | * @throws \Exception Is thrown, if the tax class with the requested name is not available |
||
| 381 | */ |
||
| 382 | View Code Duplication | public function getTaxClassIdByTaxClassName($taxClassName) |
|
| 397 | |||
| 398 | /** |
||
| 399 | * Return's the store website for the passed code. |
||
| 400 | * |
||
| 401 | * @param string $code The code of the store website to return the ID for |
||
| 402 | * |
||
| 403 | * @return integer The store website ID |
||
| 404 | * @throws \Exception Is thrown, if the store website with the requested code is not available |
||
| 405 | */ |
||
| 406 | View Code Duplication | public function getStoreWebsiteIdByCode($code) |
|
| 421 | |||
| 422 | /** |
||
| 423 | * Return's the category with the passed path. |
||
| 424 | * |
||
| 425 | * @param string $path The path of the category to return |
||
| 426 | * |
||
| 427 | * @return array The category |
||
| 428 | * @throws \Exception Is thrown, if the requested category is not available |
||
| 429 | */ |
||
| 430 | public function getCategoryByPath($path) |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Return's the category with the passed ID. |
||
| 448 | * |
||
| 449 | * @param integer $categoryId The ID of the category to return |
||
| 450 | * |
||
| 451 | * @return array The category data |
||
| 452 | * @throws \Exception Is thrown, if the category is not available |
||
| 453 | */ |
||
| 454 | public function getCategory($categoryId) |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Return's the root category for the actual view store. |
||
| 474 | * |
||
| 475 | * @return array The store's root category |
||
| 476 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
| 477 | */ |
||
| 478 | public function getRootCategory() |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Returns an array with the codes of the store views related with the passed website code. |
||
| 502 | * |
||
| 503 | * @param string $websiteCode The code of the website to return the store view codes for |
||
| 504 | * |
||
| 505 | * @return array The array with the matching store view codes |
||
| 506 | */ |
||
| 507 | public function getStoreViewCodesByWebsiteCode($websiteCode) |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Merge the columns from the configuration with all image type columns to define which |
||
| 539 | * columns should be cleaned-up. |
||
| 540 | * |
||
| 541 | * @return array The columns that has to be cleaned-up |
||
| 542 | */ |
||
| 543 | public function getCleanUpColumns() |
||
| 565 | } |
||
| 566 |