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