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