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 |
||
| 44 | class BunchSubject extends AbstractCategorySubject implements ExportableSubjectInterface, FileUploadSubjectInterface, UrlKeyAwareSubjectInterface, CleanUpColumnsSubjectInterface |
||
|
|
|||
| 45 | { |
||
| 46 | |||
| 47 | /** |
||
| 48 | * The trait that implements the export functionality. |
||
| 49 | * |
||
| 50 | * @var \TechDivision\Import\Subjects\ExportableTrait |
||
| 51 | */ |
||
| 52 | use ExportableTrait; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * The trait that provides file upload functionality. |
||
| 56 | * |
||
| 57 | * @var \TechDivision\Import\Subjects\FileUploadTrait |
||
| 58 | */ |
||
| 59 | use FileUploadTrait; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * The array with the available display mode keys. |
||
| 63 | * |
||
| 64 | * @var array |
||
| 65 | */ |
||
| 66 | protected $availableDisplayModes = array( |
||
| 67 | 'Products only' => DisplayModeKeys::DISPLAY_MODE_PRODUCTS_ONLY, |
||
| 68 | 'Static block only' => DisplayModeKeys::DISPLAY_MODE_STATIC_BLOCK_ONLY, |
||
| 69 | 'Static block and products' => DisplayModeKeys::DISPLAY_MODE_BOTH |
||
| 70 | ); |
||
| 71 | |||
| 72 | /** |
||
| 73 | * The array with the available page layout keys. |
||
| 74 | * |
||
| 75 | * @var array |
||
| 76 | */ |
||
| 77 | protected $availablePageLayouts = array( |
||
| 78 | '1 column' => PageLayoutKeys::PAGE_LAYOUT_1_COLUMN, |
||
| 79 | '2 columns with left bar' => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_LEFT, |
||
| 80 | '2 columns with right bar' => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_RIGHT, |
||
| 81 | '3 columns' => PageLayoutKeys::PAGE_LAYOUT_3_COLUMNS, |
||
| 82 | 'Empty' => PageLayoutKeys::PAGE_LAYOUT_EMPTY |
||
| 83 | ); |
||
| 84 | /** |
||
| 85 | * The default callback mappings for the Magento standard category attributes. |
||
| 86 | * |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | protected $defaultCallbackMappings = array( |
||
| 90 | 'display_mode' => array('import_category.callback.display.mode'), |
||
| 91 | 'page_layout' => array('import_category.callback.page.layout'), |
||
| 92 | ); |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The available entity types. |
||
| 96 | * |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | protected $entityTypes = array(); |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 103 | * |
||
| 104 | * @param string $serial The serial of the actual import |
||
| 105 | * |
||
| 106 | * @return void |
||
| 107 | */ |
||
| 108 | public function setUp($serial) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Return's the default callback mappings. |
||
| 151 | * |
||
| 152 | * @return array The default callback mappings |
||
| 153 | */ |
||
| 154 | public function getDefaultCallbackMappings() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Return's the display mode for the passed display mode string. |
||
| 161 | * |
||
| 162 | * @param string $displayMode The display mode string to return the key for |
||
| 163 | * |
||
| 164 | * @return integer The requested display mode |
||
| 165 | * @throws \Exception Is thrown, if the requested display mode is not available |
||
| 166 | */ |
||
| 167 | public function getDisplayModeByValue($displayMode) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Return's the page layout for the passed page layout string. |
||
| 185 | * |
||
| 186 | * @param string $pageLayout The page layout string to return the key for |
||
| 187 | * |
||
| 188 | * @return integer The requested page layout |
||
| 189 | * @throws \Exception Is thrown, if the requested page layout is not available |
||
| 190 | */ |
||
| 191 | public function getPageLayoutByValue($pageLayout) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Return's the available store view codes of the available stores. |
||
| 209 | * |
||
| 210 | * @return array The array with the available store view codes |
||
| 211 | */ |
||
| 212 | public function getStoreViewCodes() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Returns the store view codes relevant to the category represented by the current row. |
||
| 219 | * |
||
| 220 | * @param string $path The path to return the root category's store view codes for |
||
| 221 | * |
||
| 222 | * @return array The store view codes for the given root category |
||
| 223 | * @throws \Exception Is thrown, if the root category of the passed path is NOT available |
||
| 224 | */ |
||
| 225 | public function getRootCategoryStoreViewCodes($path) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Return's the PK column name to create the product => attribute relation. |
||
| 258 | * |
||
| 259 | * @return string The PK column name |
||
| 260 | */ |
||
| 261 | protected function getPrimaryKeyMemberName() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Return's the entity type for the configured entity type code. |
||
| 268 | * |
||
| 269 | * @return array The requested entity type |
||
| 270 | * @throws \Exception Is thrown, if the requested entity type is not available |
||
| 271 | */ |
||
| 272 | View Code Duplication | public function getEntityType() |
|
| 287 | |||
| 288 | /** |
||
| 289 | * Merge the columns from the configuration with all image type columns to define which |
||
| 290 | * columns should be cleaned-up. |
||
| 291 | * |
||
| 292 | * @return array The columns that has to be cleaned-up |
||
| 293 | */ |
||
| 294 | public function getCleanUpColumns() |
||
| 308 | } |
||
| 309 |