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 |
||
| 48 | class BunchSubject extends AbstractProductSubject implements ExportableSubjectInterface, FileUploadSubjectInterface, UrlKeyAwareSubjectInterface |
||
| 49 | { |
||
| 50 | |||
| 51 | /** |
||
| 52 | * The trait that implements the export functionality. |
||
| 53 | * |
||
| 54 | * @var \TechDivision\Import\Subjects\ExportableTrait |
||
| 55 | */ |
||
| 56 | use ExportableTrait; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * The trait that provides file upload functionality. |
||
| 60 | * |
||
| 61 | * @var \TechDivision\Import\Subjects\FileUploadTrait |
||
| 62 | */ |
||
| 63 | use FileUploadTrait; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * The array with the pre-loaded entity IDs. |
||
| 67 | * |
||
| 68 | * @var array |
||
| 69 | */ |
||
| 70 | protected $preLoadedEntityIds = array(); |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Mappings for the table column => CSV column header. |
||
| 74 | * |
||
| 75 | * @var array |
||
| 76 | */ |
||
| 77 | protected $headerStockMappings = array( |
||
| 78 | 'qty' => array('qty', 'float'), |
||
| 79 | 'min_qty' => array('out_of_stock_qty', 'float'), |
||
| 80 | 'use_config_min_qty' => array('use_config_min_qty', 'int'), |
||
| 81 | 'is_qty_decimal' => array('is_qty_decimal', 'int'), |
||
| 82 | 'backorders' => array('allow_backorders', 'int'), |
||
| 83 | 'use_config_backorders' => array('use_config_backorders', 'int'), |
||
| 84 | 'min_sale_qty' => array('min_cart_qty', 'float'), |
||
| 85 | 'use_config_min_sale_qty' => array('use_config_min_sale_qty', 'int'), |
||
| 86 | 'max_sale_qty' => array('max_cart_qty', 'float'), |
||
| 87 | 'use_config_max_sale_qty' => array('use_config_max_sale_qty', 'int'), |
||
| 88 | 'is_in_stock' => array('is_in_stock', 'int'), |
||
| 89 | 'notify_stock_qty' => array('notify_on_stock_below', 'float'), |
||
| 90 | 'use_config_notify_stock_qty' => array('use_config_notify_stock_qty', 'int'), |
||
| 91 | 'manage_stock' => array('manage_stock', 'int'), |
||
| 92 | 'use_config_manage_stock' => array('use_config_manage_stock', 'int'), |
||
| 93 | 'use_config_qty_increments' => array('use_config_qty_increments', 'int'), |
||
| 94 | 'qty_increments' => array('qty_increments', 'float'), |
||
| 95 | 'use_config_enable_qty_inc' => array('use_config_enable_qty_inc', 'int'), |
||
| 96 | 'enable_qty_increments' => array('enable_qty_increments', 'int'), |
||
| 97 | 'is_decimal_divided' => array('is_decimal_divided', 'int'), |
||
| 98 | ); |
||
| 99 | |||
| 100 | /** |
||
| 101 | * The array with the available visibility keys. |
||
| 102 | * |
||
| 103 | * @var array |
||
| 104 | */ |
||
| 105 | protected $availableVisibilities = array( |
||
| 106 | 'Not Visible Individually' => VisibilityKeys::VISIBILITY_NOT_VISIBLE, |
||
| 107 | 'Catalog' => VisibilityKeys::VISIBILITY_IN_CATALOG, |
||
| 108 | 'Search' => VisibilityKeys::VISIBILITY_IN_SEARCH, |
||
| 109 | 'Catalog, Search' => VisibilityKeys::VISIBILITY_BOTH |
||
| 110 | ); |
||
| 111 | |||
| 112 | /** |
||
| 113 | * The default callback mappings for the Magento standard product attributes. |
||
| 114 | * |
||
| 115 | * @var array |
||
| 116 | */ |
||
| 117 | protected $defaultCallbackMappings = array( |
||
| 118 | 'visibility' => array('import_product.callback.visibility'), |
||
| 119 | 'tax_class_id' => array('import_product.callback.tax.class'), |
||
| 120 | 'bundle_price_type' => array('import_product_bundle.callback.bundle.type'), |
||
| 121 | 'bundle_sku_type' => array('import_product_bundle.callback.bundle.type'), |
||
| 122 | 'bundle_weight_type' => array('import_product_bundle.callback.bundle.type'), |
||
| 123 | 'bundle_price_view' => array('import_product_bundle.callback.bundle.price.view'), |
||
| 124 | 'bundle_shipment_type' => array('import_product_bundle.callback.bundle.shipment.type') |
||
| 125 | ); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * The available entity types. |
||
| 129 | * |
||
| 130 | * @var array |
||
| 131 | */ |
||
| 132 | protected $entityTypes = array(); |
||
| 133 | |||
| 134 | /** |
||
| 135 | * The media roles loader instance. |
||
| 136 | * |
||
| 137 | * @var \TechDivision\Import\Loaders\LoaderInterface |
||
| 138 | */ |
||
| 139 | protected $mediaRolesLoader; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * BunchSubject constructor |
||
| 143 | * |
||
| 144 | * @param RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 145 | * @param GeneratorInterface $coreConfigDataUidGenerator The generator instance |
||
| 146 | * @param Collection $systemLoggers The system logger collection |
||
| 147 | * @param EmitterInterface $emitter The emitter instance |
||
| 148 | * @param LoaderInterface $loader The media type loader instance |
||
| 149 | */ |
||
| 150 | 18 | public function __construct( |
|
| 164 | |||
| 165 | /** |
||
| 166 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 167 | * |
||
| 168 | * @param string $serial The serial of the actual import |
||
| 169 | * |
||
| 170 | * @return void |
||
| 171 | */ |
||
| 172 | 18 | public function setUp($serial) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * Clean up the global data after importing the bunch. |
||
| 210 | * |
||
| 211 | * @param string $serial The serial of the actual import |
||
| 212 | * |
||
| 213 | * @return void |
||
| 214 | */ |
||
| 215 | public function tearDown($serial) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Return's the default callback mappings. |
||
| 235 | * |
||
| 236 | * @return array The default callback mappings |
||
| 237 | */ |
||
| 238 | public function getDefaultCallbackMappings() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Return's the mappings for the table column => CSV column header. |
||
| 245 | * |
||
| 246 | * @return array The header stock mappings |
||
| 247 | */ |
||
| 248 | 1 | public function getHeaderStockMappings() |
|
| 252 | |||
| 253 | /** |
||
| 254 | * Return's the visibility key for the passed visibility string. |
||
| 255 | * |
||
| 256 | * @param string $visibility The visibility string to return the key for |
||
| 257 | * |
||
| 258 | * @return integer The requested visibility key |
||
| 259 | * @throws \Exception Is thrown, if the requested visibility is not available |
||
| 260 | */ |
||
| 261 | public function getVisibilityIdByValue($visibility) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Pre-load the entity ID for the passed product. |
||
| 280 | * |
||
| 281 | * @param array $product The product to be pre-loaded |
||
| 282 | * |
||
| 283 | * @return void |
||
| 284 | */ |
||
| 285 | public function preLoadEntityId(array $product) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Return's the entity type for the configured entity type code. |
||
| 292 | * |
||
| 293 | * @return array The requested entity type |
||
| 294 | * @throws \Exception Is thrown, if the requested entity type is not available |
||
| 295 | */ |
||
| 296 | 1 | View Code Duplication | public function getEntityType() |
| 311 | |||
| 312 | /** |
||
| 313 | * Return's TRUE, if the passed URL key varchar value IS related with the actual PK. |
||
| 314 | * |
||
| 315 | * @param array $productVarcharAttribute The varchar value to check |
||
| 316 | * |
||
| 317 | * @return boolean TRUE if the URL key is related, else FALSE |
||
| 318 | */ |
||
| 319 | public function isUrlKeyOf(array $productVarcharAttribute) |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Loads and returns the media roles. |
||
| 327 | * |
||
| 328 | * @return array The array with the media roles |
||
| 329 | */ |
||
| 330 | public function getMediaRoles(): array |
||
| 334 | } |
||
| 335 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: