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 |
||
43 | class BunchSubject extends AbstractProductSubject implements ExportableSubjectInterface, FileUploadSubjectInterface, UrlKeyAwareSubjectInterface |
||
44 | { |
||
45 | |||
46 | /** |
||
47 | * The trait that implements the export functionality. |
||
48 | * |
||
49 | * @var \TechDivision\Import\Subjects\ExportableTrait |
||
50 | */ |
||
51 | use ExportableTrait; |
||
52 | |||
53 | /** |
||
54 | * The trait that provides file upload functionality. |
||
55 | * |
||
56 | * @var \TechDivision\Import\Subjects\FileUploadTrait |
||
57 | */ |
||
58 | use FileUploadTrait; |
||
59 | |||
60 | /** |
||
61 | * The array with the pre-loaded entity IDs. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $preLoadedEntityIds = array(); |
||
66 | |||
67 | /** |
||
68 | * Mappings for the table column => CSV column header. |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $headerStockMappings = array( |
||
73 | 'qty' => array('qty', 'float'), |
||
74 | 'min_qty' => array('out_of_stock_qty', 'float'), |
||
75 | 'use_config_min_qty' => array('use_config_min_qty', 'int'), |
||
76 | 'is_qty_decimal' => array('is_qty_decimal', 'int'), |
||
77 | 'backorders' => array('allow_backorders', 'int'), |
||
78 | 'use_config_backorders' => array('use_config_backorders', 'int'), |
||
79 | 'min_sale_qty' => array('min_cart_qty', 'float'), |
||
80 | 'use_config_min_sale_qty' => array('use_config_min_sale_qty', 'int'), |
||
81 | 'max_sale_qty' => array('max_cart_qty', 'float'), |
||
82 | 'use_config_max_sale_qty' => array('use_config_max_sale_qty', 'int'), |
||
83 | 'is_in_stock' => array('is_in_stock', 'int'), |
||
84 | 'notify_stock_qty' => array('notify_on_stock_below', 'float'), |
||
85 | 'use_config_notify_stock_qty' => array('use_config_notify_stock_qty', 'int'), |
||
86 | 'manage_stock' => array('manage_stock', 'int'), |
||
87 | 'use_config_manage_stock' => array('use_config_manage_stock', 'int'), |
||
88 | 'use_config_qty_increments' => array('use_config_qty_increments', 'int'), |
||
89 | 'qty_increments' => array('qty_increments', 'float'), |
||
90 | 'use_config_enable_qty_inc' => array('use_config_enable_qty_inc', 'int'), |
||
91 | 'enable_qty_increments' => array('enable_qty_increments', 'int'), |
||
92 | 'is_decimal_divided' => array('is_decimal_divided', 'int'), |
||
93 | ); |
||
94 | |||
95 | /** |
||
96 | * The array with the available visibility keys. |
||
97 | * |
||
98 | * @var array |
||
99 | */ |
||
100 | protected $availableVisibilities = array( |
||
101 | 'Not Visible Individually' => VisibilityKeys::VISIBILITY_NOT_VISIBLE, |
||
102 | 'Catalog' => VisibilityKeys::VISIBILITY_IN_CATALOG, |
||
103 | 'Search' => VisibilityKeys::VISIBILITY_IN_SEARCH, |
||
104 | 'Catalog, Search' => VisibilityKeys::VISIBILITY_BOTH |
||
105 | ); |
||
106 | |||
107 | /** |
||
108 | * The default callback mappings for the Magento standard product attributes. |
||
109 | * |
||
110 | * @var array |
||
111 | */ |
||
112 | protected $defaultCallbackMappings = array( |
||
113 | 'visibility' => array('import_product.callback.visibility'), |
||
114 | 'tax_class_id' => array('import_product.callback.tax.class'), |
||
115 | 'bundle_price_type' => array('import_product_bundle.callback.bundle.type'), |
||
116 | 'bundle_sku_type' => array('import_product_bundle.callback.bundle.type'), |
||
117 | 'bundle_weight_type' => array('import_product_bundle.callback.bundle.type'), |
||
118 | 'bundle_price_view' => array('import_product_bundle.callback.bundle.price.view'), |
||
119 | 'bundle_shipment_type' => array('import_product_bundle.callback.bundle.shipment.type') |
||
120 | ); |
||
121 | |||
122 | /** |
||
123 | * The available entity types. |
||
124 | * |
||
125 | * @var array |
||
126 | */ |
||
127 | protected $entityTypes = array(); |
||
128 | |||
129 | /** |
||
130 | * Intializes the previously loaded global data for exactly one bunch. |
||
131 | * |
||
132 | * @param string $serial The serial of the actual import |
||
133 | * |
||
134 | * @return void |
||
135 | */ |
||
136 | 18 | public function setUp($serial) |
|
137 | { |
||
138 | |||
139 | // load the status of the actual import |
||
140 | 18 | $status = $this->getRegistryProcessor()->getAttribute(RegistryKeys::STATUS); |
|
141 | |||
142 | // load the global data we've prepared initially |
||
143 | 18 | $this->entityTypes = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::ENTITY_TYPES]; |
|
144 | |||
145 | // initialize the flag whether to copy images or not |
||
146 | 18 | if ($this->getConfiguration()->hasParam(ConfigurationKeys::COPY_IMAGES)) { |
|
147 | $this->setCopyImages($this->getConfiguration()->getParam(ConfigurationKeys::COPY_IMAGES)); |
||
|
|||
148 | } |
||
149 | |||
150 | // initialize media directory => can be absolute or relative |
||
151 | 18 | if ($this->getConfiguration()->hasParam(ConfigurationKeys::MEDIA_DIRECTORY)) { |
|
152 | $this->setMediaDir( |
||
153 | $this->resolvePath( |
||
154 | $this->getConfiguration()->getParam(ConfigurationKeys::MEDIA_DIRECTORY) |
||
155 | ) |
||
156 | ); |
||
157 | } |
||
158 | |||
159 | // initialize images directory => can be absolute or relative |
||
160 | 18 | if ($this->getConfiguration()->hasParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)) { |
|
161 | $this->setImagesFileDir( |
||
162 | $this->resolvePath( |
||
163 | $this->getConfiguration()->getParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY) |
||
164 | ) |
||
165 | ); |
||
166 | } |
||
167 | |||
168 | // invoke the parent method |
||
169 | 18 | parent::setUp($serial); |
|
170 | 18 | } |
|
171 | |||
172 | /** |
||
173 | * Clean up the global data after importing the bunch. |
||
174 | * |
||
175 | * @param string $serial The serial of the actual import |
||
176 | * |
||
177 | * @return void |
||
178 | */ |
||
179 | public function tearDown($serial) |
||
196 | |||
197 | /** |
||
198 | * Return's the default callback mappings. |
||
199 | * |
||
200 | * @return array The default callback mappings |
||
201 | */ |
||
202 | public function getDefaultCallbackMappings() |
||
206 | |||
207 | /** |
||
208 | * Return's the mappings for the table column => CSV column header. |
||
209 | * |
||
210 | * @return array The header stock mappings |
||
211 | */ |
||
212 | 1 | public function getHeaderStockMappings() |
|
216 | |||
217 | /** |
||
218 | * Return's the visibility key for the passed visibility string. |
||
219 | * |
||
220 | * @param string $visibility The visibility string to return the key for |
||
221 | * |
||
222 | * @return integer The requested visibility key |
||
223 | * @throws \Exception Is thrown, if the requested visibility is not available |
||
224 | */ |
||
225 | public function getVisibilityIdByValue($visibility) |
||
241 | |||
242 | /** |
||
243 | * Pre-load the entity ID for the passed product. |
||
244 | * |
||
245 | * @param array $product The product to be pre-loaded |
||
246 | * |
||
247 | * @return void |
||
248 | */ |
||
249 | public function preLoadEntityId(array $product) |
||
253 | |||
254 | /** |
||
255 | * Return's the entity type for the configured entity type code. |
||
256 | * |
||
257 | * @return array The requested entity type |
||
258 | * @throws \Exception Is thrown, if the requested entity type is not available |
||
259 | */ |
||
260 | 1 | View Code Duplication | public function getEntityType() |
261 | { |
||
262 | |||
263 | // query whether or not the entity type with the passed code is available |
||
264 | 1 | if (isset($this->entityTypes[$entityTypeCode = $this->getEntityTypeCode()])) { |
|
265 | 1 | return $this->entityTypes[$entityTypeCode]; |
|
266 | } |
||
267 | |||
268 | // throw a new exception |
||
269 | throw new \Exception( |
||
270 | $this->appendExceptionSuffix( |
||
271 | sprintf('Requested entity type "%s" is not available', $entityTypeCode) |
||
272 | ) |
||
273 | ); |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * Return's TRUE, if the passed URL key varchar value IS related with the actual PK. |
||
278 | * |
||
279 | * @param array $productVarcharAttribute The varchar value to check |
||
280 | * |
||
281 | * @return boolean TRUE if the URL key is related, else FALSE |
||
282 | */ |
||
283 | public function isUrlKeyOf(array $productVarcharAttribute) |
||
288 | } |
||
289 |
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: