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 |
||
41 | class CatalogAttributeObserver extends AbstractAttributeImportObserver |
||
42 | { |
||
43 | |||
44 | /** |
||
45 | * The key for the additional data containing the swatch type. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | const SWATCH_INPUT_TYPE = 'swatch_input_type'; |
||
50 | |||
51 | /** |
||
52 | * The available swatch types. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $swatchTypes = array('text', 'visual', 'image'); |
||
57 | |||
58 | /** |
||
59 | * The attribute processor instance. |
||
60 | * |
||
61 | * @var \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface |
||
62 | */ |
||
63 | protected $attributeBunchProcessor; |
||
64 | |||
65 | /** |
||
66 | * The collection with entity merger instances. |
||
67 | * |
||
68 | * @var \Doctrine\Common\Collections\Collection |
||
69 | */ |
||
70 | protected $entityMergers; |
||
71 | |||
72 | /** |
||
73 | * Array with virtual column name mappings (this is a temporary |
||
74 | * solution till techdivision/import#179 as been implemented). |
||
75 | * |
||
76 | * @var array |
||
77 | * @todo https://github.com/techdivision/import/issues/179 |
||
78 | */ |
||
79 | protected $reverseHeaderMappings = array(); |
||
80 | |||
81 | /** |
||
82 | * Initializes the observer with the passed subject instance. |
||
83 | * |
||
84 | * @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance |
||
85 | * @param \TechDivision\Import\Observers\EntityMergers\EntityMergerInterface $entityMerger The entity merger instance |
||
86 | * @param \TechDivision\Import\Loaders\LoaderInterface|null $headerMappingLoader The loader for the virtual mappings |
||
87 | * @param \TechDivision\Import\Observers\StateDetectorInterface|null $stateDetector The state detector instance to use |
||
88 | */ |
||
89 | 3 | public function __construct( |
|
109 | |||
110 | /** |
||
111 | * Process the observer's business logic. |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | 3 | protected function process() |
|
126 | |||
127 | /** |
||
128 | * Merge's and return's the entity with the passed attributes and set's the |
||
129 | * passed status. |
||
130 | * |
||
131 | * @param array $entity The entity to merge the attributes into |
||
132 | * @param array $attr The attributes to be merged |
||
133 | * @param string|null $changeSetName The change set name to use |
||
134 | * |
||
135 | * @return array The merged entity |
||
136 | * @todo https://github.com/techdivision/import/issues/179 |
||
137 | */ |
||
138 | 2 | View Code Duplication | protected function mergeEntity(array $entity, array $attr, $changeSetName = null) |
146 | |||
147 | /** |
||
148 | * Prepare the attributes of the entity that has to be persisted. |
||
149 | * |
||
150 | * @return array The prepared attributes |
||
151 | * @throws \Exception Is thrown, if the size of the option values doesn't equals the size of swatch values, in case |
||
152 | */ |
||
153 | 3 | protected function prepareAttributes() |
|
219 | |||
220 | /** |
||
221 | * Serialize the additional_data attribute of the passed array. |
||
222 | * |
||
223 | * @param array $attr The attribute with the data to serialize |
||
224 | * |
||
225 | * @return array The attribute with the serialized additional_data |
||
226 | */ |
||
227 | 3 | protected function serializeAdditionalData(array $attr) |
|
238 | |||
239 | /** |
||
240 | * Load's and return's a raw customer entity without primary key but the mandatory members only and nulled values. |
||
241 | * |
||
242 | * @param array $data An array with data that will be used to initialize the raw entity with |
||
243 | * |
||
244 | * @return array The initialized entity |
||
245 | */ |
||
246 | 3 | protected function loadRawEntity(array $data = array()) |
|
250 | |||
251 | /** |
||
252 | * Initialize the attribute with the passed attributes and returns an instance. |
||
253 | * |
||
254 | * @param array $attr The attribute attributes |
||
255 | * |
||
256 | * @return array The initialized attribute |
||
257 | */ |
||
258 | 1 | protected function initializeAttribute(array $attr) |
|
262 | |||
263 | /** |
||
264 | * Return's the attribute bunch processor instance. |
||
265 | * |
||
266 | * @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance |
||
267 | */ |
||
268 | 3 | protected function getAttributeBunchProcessor() |
|
272 | |||
273 | /** |
||
274 | * Map's the passed attribute code to the attribute ID that has been created recently. |
||
275 | * |
||
276 | * @param string $attributeCode The attribute code that has to be mapped |
||
277 | * |
||
278 | * @return void |
||
279 | */ |
||
280 | protected function addAttributeCodeIdMapping($attributeCode) |
||
284 | |||
285 | /** |
||
286 | * Queries whether or not the attribute with the passed code has already been processed. |
||
287 | * |
||
288 | * @param string $attributeCode The attribute code to check |
||
289 | * |
||
290 | * @return boolean TRUE if the path has been processed, else FALSE |
||
291 | */ |
||
292 | 3 | protected function hasBeenProcessed($attributeCode) |
|
296 | |||
297 | /** |
||
298 | * Return's the ID of the attribute that has been created recently. |
||
299 | * |
||
300 | * @return integer The attribute ID |
||
301 | */ |
||
302 | 3 | protected function getLastAttributeId() |
|
306 | |||
307 | /** |
||
308 | * Return's TRUE if the additional data contains a swatch type. |
||
309 | * |
||
310 | * @param array $additionalData The additional data to query for a valid swatch type |
||
311 | * |
||
312 | * @return boolean TRUE if the data contains a swatch type, else FALSE |
||
313 | */ |
||
314 | 1 | protected function isSwatchType(array $additionalData) |
|
318 | |||
319 | /** |
||
320 | * Persist the passed EAV catalog attribute. |
||
321 | * |
||
322 | * @param array $catalogAttribute The EAV catalog attribute to persist |
||
323 | * |
||
324 | * @return void |
||
325 | */ |
||
326 | 3 | protected function persistCatalogAttribute(array $catalogAttribute) |
|
330 | } |
||
331 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.