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 AbstractSubject |
||
| 40 | { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The processor to read/write the necessary product data. |
||
| 44 | * |
||
| 45 | * @var \TechDivision\Import\Product\Services\ProductProcessorInterface |
||
| 46 | */ |
||
| 47 | protected $productProcessor; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The available EAV attribute sets. |
||
| 51 | * |
||
| 52 | * @var array |
||
| 53 | */ |
||
| 54 | protected $attributeSets = array(); |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The available stores. |
||
| 58 | * |
||
| 59 | * @var array |
||
| 60 | */ |
||
| 61 | protected $stores = array(); |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The available store websites. |
||
| 65 | * |
||
| 66 | * @var array |
||
| 67 | */ |
||
| 68 | protected $storeWebsites = array(); |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The available EAV attributes, grouped by their attribute set and the attribute set name as keys. |
||
| 72 | * |
||
| 73 | * @var array |
||
| 74 | */ |
||
| 75 | protected $attributes = array(); |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The available tax classes. |
||
| 79 | * |
||
| 80 | * @var array |
||
| 81 | */ |
||
| 82 | protected $taxClasses = array(); |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The available categories. |
||
| 86 | * |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | protected $categories = array(); |
||
| 90 | |||
| 91 | /** |
||
| 92 | * The available root categories. |
||
| 93 | * |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | protected $rootCategories = array(); |
||
| 97 | |||
| 98 | /** |
||
| 99 | * The ID of the product that has been created recently. |
||
| 100 | * |
||
| 101 | * @var string |
||
| 102 | */ |
||
| 103 | protected $lastEntityId; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * The SKU of the product that has been created recently. |
||
| 107 | * |
||
| 108 | * @var string |
||
| 109 | */ |
||
| 110 | protected $lastSku; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * The store view code the create the product/attributes for. |
||
| 114 | * |
||
| 115 | * @var string |
||
| 116 | */ |
||
| 117 | protected $storeViewCode; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * The default store. |
||
| 121 | * |
||
| 122 | * @var array |
||
| 123 | */ |
||
| 124 | protected $defaultStore; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Set's the product processor instance. |
||
| 128 | * |
||
| 129 | * @param \TechDivision\Import\Product\Services\ProductProcessorInterface $productProcessor The product processor instance |
||
| 130 | * |
||
| 131 | * @return void |
||
| 132 | */ |
||
| 133 | 3 | public function setProductProcessor(ProductProcessorInterface $productProcessor) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * Return's the product processor instance. |
||
| 140 | * |
||
| 141 | * @return \TechDivision\Import\Services\ProductProcessorInterface The product processor instance |
||
| 142 | */ |
||
| 143 | 3 | public function getProductProcessor() |
|
| 147 | |||
| 148 | /** |
||
| 149 | * Set's the SKU of the last imported product. |
||
| 150 | * |
||
| 151 | * @param string $lastSku The SKU |
||
| 152 | * |
||
| 153 | * @return void |
||
| 154 | */ |
||
| 155 | public function setLastSku($lastSku) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Return's the SKU of the last imported product. |
||
| 162 | * |
||
| 163 | * @return string|null The SKU |
||
| 164 | */ |
||
| 165 | public function getLastSku() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Set's the ID of the product that has been created recently. |
||
| 172 | * |
||
| 173 | * @param string $lastEntityId The entity ID |
||
| 174 | * |
||
| 175 | * @return void |
||
| 176 | */ |
||
| 177 | public function setLastEntityId($lastEntityId) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Return's the ID of the product that has been created recently. |
||
| 184 | * |
||
| 185 | * @return string The entity Id |
||
| 186 | */ |
||
| 187 | public function getLastEntityId() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Set's the store view code the create the product/attributes for. |
||
| 194 | * |
||
| 195 | * @param string $storeViewCode The store view code |
||
| 196 | * |
||
| 197 | * @return void |
||
| 198 | */ |
||
| 199 | 3 | public function setStoreViewCode($storeViewCode) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * Return's the store view code the create the product/attributes for. |
||
| 206 | * |
||
| 207 | * @param string|null $default The default value to return, if the store view code has not been set |
||
| 208 | * |
||
| 209 | * @return string The store view code |
||
| 210 | */ |
||
| 211 | public function getStoreViewCode($default = null) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Return's the default store. |
||
| 228 | * |
||
| 229 | * @return array The default store |
||
| 230 | */ |
||
| 231 | public function getDefaultStore() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 238 | * |
||
| 239 | * @return void |
||
| 240 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 241 | */ |
||
| 242 | public function setUp() |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Clean up the global data after importing the bunch. |
||
| 264 | * |
||
| 265 | * @return void |
||
| 266 | */ |
||
| 267 | public function tearDown() |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Return's the attributes for the attribute set of the product that has to be created. |
||
| 286 | * |
||
| 287 | * @return array The attributes |
||
| 288 | * @throws \Exception Is thrown if the attributes for the actual attribute set are not available |
||
| 289 | */ |
||
| 290 | public function getAttributes() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Return's the store ID of the actual row. |
||
| 307 | * |
||
| 308 | * @return integer The ID of the actual store |
||
| 309 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
| 310 | */ |
||
| 311 | View Code Duplication | public function getRowStoreId() |
|
| 325 | |||
| 326 | /** |
||
| 327 | * Return's the tax class ID for the passed tax class name. |
||
| 328 | * |
||
| 329 | * @param string $taxClassName The tax class name to return the ID for |
||
| 330 | * |
||
| 331 | * @return integer The tax class ID |
||
| 332 | * @throws \Exception Is thrown, if the tax class with the requested name is not available |
||
| 333 | */ |
||
| 334 | View Code Duplication | public function getTaxClassIdByTaxClassName($taxClassName) |
|
| 345 | |||
| 346 | /** |
||
| 347 | * Return's the store website for the passed code. |
||
| 348 | * |
||
| 349 | * @param string $code The code of the store website to return the ID for |
||
| 350 | * |
||
| 351 | * @return integer The store website ID |
||
| 352 | * @throws \Exception Is thrown, if the store website with the requested code is not available |
||
| 353 | */ |
||
| 354 | View Code Duplication | public function getStoreWebsiteIdByCode($code) |
|
| 365 | |||
| 366 | /** |
||
| 367 | * Return's the attribute set with the passed attribute set name. |
||
| 368 | * |
||
| 369 | * @param string $attributeSetName The name of the requested attribute set |
||
| 370 | * |
||
| 371 | * @return array The attribute set data |
||
| 372 | * @throws \Exception Is thrown, if the attribute set with the passed name is not available |
||
| 373 | */ |
||
| 374 | public function getAttributeSetByAttributeSetName($attributeSetName) |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Return's the category with the passed path. |
||
| 387 | * |
||
| 388 | * @param string $path The path of the category to return |
||
| 389 | * |
||
| 390 | * @return array The category |
||
| 391 | * @throws \Exception Is thrown, if the requested category is not available |
||
| 392 | */ |
||
| 393 | public function getCategoryByPath($path) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Return's the category with the passed ID. |
||
| 407 | * |
||
| 408 | * @param integer $categoryId The ID of the category to return |
||
| 409 | * |
||
| 410 | * @return array The category data |
||
| 411 | * @throws \Exception Is thrown, if the category is not available |
||
| 412 | */ |
||
| 413 | public function getCategory($categoryId) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Return's the root category for the actual view store. |
||
| 429 | * |
||
| 430 | * @return array The store's root category |
||
| 431 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
| 432 | */ |
||
| 433 | public function getRootCategory() |
||
| 450 | } |
||
| 451 |