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 |
||
50 | class BunchSubject extends AbstractProductSubject implements ExportableSubjectInterface, FileUploadSubjectInterface, UrlKeyAwareSubjectInterface, CleanUpColumnsSubjectInterface |
||
51 | { |
||
52 | |||
53 | /** |
||
54 | * The trait that implements the export functionality. |
||
55 | * |
||
56 | * @var \TechDivision\Import\Subjects\ExportableTrait |
||
57 | */ |
||
58 | use ExportableTrait; |
||
59 | |||
60 | /** |
||
61 | * The trait that provides file upload functionality. |
||
62 | * |
||
63 | * @var \TechDivision\Import\Subjects\FileUploadTrait |
||
64 | */ |
||
65 | use FileUploadTrait; |
||
66 | |||
67 | /** |
||
68 | * The array with the pre-loaded entity IDs. |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $preLoadedEntityIds = array(); |
||
73 | |||
74 | /** |
||
75 | * Mappings for the table column => CSV column header. |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | protected $headerStockMappings = array( |
||
80 | 'qty' => array('qty', 'float'), |
||
81 | 'min_qty' => array('out_of_stock_qty', 'float'), |
||
82 | 'use_config_min_qty' => array('use_config_min_qty', 'int'), |
||
83 | 'is_qty_decimal' => array('is_qty_decimal', 'int'), |
||
84 | 'backorders' => array('allow_backorders', 'int'), |
||
85 | 'use_config_backorders' => array('use_config_backorders', 'int'), |
||
86 | 'min_sale_qty' => array('min_cart_qty', 'float'), |
||
87 | 'use_config_min_sale_qty' => array('use_config_min_sale_qty', 'int'), |
||
88 | 'max_sale_qty' => array('max_cart_qty', 'float'), |
||
89 | 'use_config_max_sale_qty' => array('use_config_max_sale_qty', 'int'), |
||
90 | 'is_in_stock' => array('is_in_stock', 'int'), |
||
91 | 'notify_stock_qty' => array('notify_on_stock_below', 'float'), |
||
92 | 'use_config_notify_stock_qty' => array('use_config_notify_stock_qty', 'int'), |
||
93 | 'manage_stock' => array('manage_stock', 'int'), |
||
94 | 'use_config_manage_stock' => array('use_config_manage_stock', 'int'), |
||
95 | 'use_config_qty_increments' => array('use_config_qty_increments', 'int'), |
||
96 | 'qty_increments' => array('qty_increments', 'float'), |
||
97 | 'use_config_enable_qty_inc' => array('use_config_enable_qty_inc', 'int'), |
||
98 | 'enable_qty_increments' => array('enable_qty_increments', 'int'), |
||
99 | 'is_decimal_divided' => array('is_decimal_divided', 'int'), |
||
100 | ); |
||
101 | |||
102 | /** |
||
103 | * The array with the available visibility keys. |
||
104 | * |
||
105 | * @var array |
||
106 | */ |
||
107 | protected $availableVisibilities = array( |
||
108 | 'Not Visible Individually' => VisibilityKeys::VISIBILITY_NOT_VISIBLE, |
||
109 | 'Catalog' => VisibilityKeys::VISIBILITY_IN_CATALOG, |
||
110 | 'Search' => VisibilityKeys::VISIBILITY_IN_SEARCH, |
||
111 | 'Catalog, Search' => VisibilityKeys::VISIBILITY_BOTH |
||
112 | ); |
||
113 | |||
114 | /** |
||
115 | * The default callback mappings for the Magento standard product attributes. |
||
116 | * |
||
117 | * @var array |
||
118 | */ |
||
119 | protected $defaultCallbackMappings = array( |
||
120 | 'visibility' => array('import_product.callback.visibility'), |
||
121 | 'tax_class_id' => array('import_product.callback.tax.class'), |
||
122 | 'bundle_price_type' => array('import_product_bundle.callback.bundle.type'), |
||
123 | 'bundle_sku_type' => array('import_product_bundle.callback.bundle.type'), |
||
124 | 'bundle_weight_type' => array('import_product_bundle.callback.bundle.type'), |
||
125 | 'bundle_price_view' => array('import_product_bundle.callback.bundle.price.view'), |
||
126 | 'bundle_shipment_type' => array('import_product_bundle.callback.bundle.shipment.type') |
||
127 | ); |
||
128 | |||
129 | /** |
||
130 | * The available entity types. |
||
131 | * |
||
132 | * @var array |
||
133 | */ |
||
134 | protected $entityTypes = array(); |
||
135 | |||
136 | /** |
||
137 | * The media roles loader instance. |
||
138 | * |
||
139 | * @var \TechDivision\Import\Loaders\LoaderInterface |
||
140 | */ |
||
141 | protected $mediaRolesLoader; |
||
142 | |||
143 | /** |
||
144 | * The entity type code mapper instance. |
||
145 | * |
||
146 | * @var \TechDivision\Import\Utils\Mappings\MapperInterface |
||
147 | */ |
||
148 | protected $entityTypeCodeMapper; |
||
149 | |||
150 | /** |
||
151 | * BunchSubject constructor |
||
152 | * |
||
153 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
154 | * @param \TechDivision\Import\Utils\Generators\GeneratorInterface $coreConfigDataUidGenerator The UID generator for the core config data |
||
155 | * @param \Doctrine\Common\Collections\Collection $systemLoggers The array with the system loggers instances |
||
156 | * @param \League\Event\EmitterInterface $emitter The event emitter instance |
||
157 | * @param \TechDivision\Import\Loaders\LoaderInterface $mediaRolesLoader The media type loader instance |
||
158 | * @param \TechDivision\Import\Utils\Mappings\MapperInterface $entityTypeCodeMapper The entity type code mapper instance |
||
159 | */ |
||
160 | 18 | public function __construct( |
|
176 | |||
177 | /** |
||
178 | * Intializes the previously loaded global data for exactly one bunch. |
||
179 | * |
||
180 | * @param string $serial The serial of the actual import |
||
181 | * |
||
182 | * @return void |
||
183 | */ |
||
184 | 18 | public function setUp($serial) |
|
226 | |||
227 | /** |
||
228 | * Clean up the global data after importing the bunch. |
||
229 | * |
||
230 | * @param string $serial The serial of the actual import |
||
231 | * |
||
232 | * @return void |
||
233 | */ |
||
234 | public function tearDown($serial) |
||
251 | |||
252 | /** |
||
253 | * Return's the default callback mappings. |
||
254 | * |
||
255 | * @return array The default callback mappings |
||
256 | */ |
||
257 | public function getDefaultCallbackMappings() |
||
261 | |||
262 | /** |
||
263 | * Return's the mappings for the table column => CSV column header. |
||
264 | * |
||
265 | * @return array The header stock mappings |
||
266 | */ |
||
267 | 1 | public function getHeaderStockMappings() |
|
271 | |||
272 | /** |
||
273 | * Return's the visibility key for the passed visibility string. |
||
274 | * |
||
275 | * @param string $visibility The visibility string to return the key for |
||
276 | * |
||
277 | * @return integer The requested visibility key |
||
278 | * @throws \Exception Is thrown, if the requested visibility is not available |
||
279 | */ |
||
280 | public function getVisibilityIdByValue($visibility) |
||
296 | |||
297 | /** |
||
298 | * Pre-load the entity ID for the passed product. |
||
299 | * |
||
300 | * @param array $product The product to be pre-loaded |
||
301 | * |
||
302 | * @return void |
||
303 | */ |
||
304 | public function preLoadEntityId(array $product) |
||
308 | |||
309 | /** |
||
310 | * Return's the entity type for the configured entity type code. |
||
311 | * |
||
312 | * @return array The requested entity type |
||
313 | * @throws \Exception Is thrown, if the requested entity type is not available |
||
314 | */ |
||
315 | 1 | View Code Duplication | public function getEntityType() |
330 | |||
331 | /** |
||
332 | * Return's TRUE, if the passed URL key varchar value IS related with the actual PK. |
||
333 | * |
||
334 | * @param array $productVarcharAttribute The varchar value to check |
||
335 | * |
||
336 | * @return boolean TRUE if the URL key is related, else FALSE |
||
337 | */ |
||
338 | public function isUrlKeyOf(array $productVarcharAttribute) |
||
343 | |||
344 | /** |
||
345 | * Loads and returns the media roles. |
||
346 | * |
||
347 | * @return array The array with the media roles |
||
348 | */ |
||
349 | public function getMediaRoles(): array |
||
353 | |||
354 | /** |
||
355 | * Merge the columns from the configuration with all image type columns to define which |
||
356 | * columns should be cleaned-up. |
||
357 | * |
||
358 | * @return array The columns that has to be cleaned-up |
||
359 | */ |
||
360 | public function getCleanUpColumns() |
||
374 | |||
375 | /** |
||
376 | * Return's the entity type code to be used. |
||
377 | * |
||
378 | * @return string The entity type code to be used |
||
379 | */ |
||
380 | 18 | public function getEntityTypeCode() |
|
384 | } |
||
385 |
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: