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 |
||
35 | View Code Duplication | class AttributeOptionUpdateObserver extends AttributeOptionObserver |
|
|
|||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Initialize the EAV attribute option with the passed attributes and returns an instance. |
||
40 | * |
||
41 | * @param array $attr The EAV attribute option attributes |
||
42 | * |
||
43 | * @return array The initialized EAV attribute option |
||
44 | */ |
||
45 | protected function initializeAttribute(array $attr) |
||
61 | |||
62 | /** |
||
63 | * Load's and return's the EAV attribute option with the passed code, store ID and value. |
||
64 | * |
||
65 | * @param string $attributeCode The code of the EAV attribute option to load |
||
66 | * @param integer $storeId The store ID of the attribute option to load |
||
67 | * @param string $value The value of the attribute option to load |
||
68 | * |
||
69 | * @return array The EAV attribute option |
||
70 | */ |
||
71 | protected function loadAttributeOptionByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value) |
||
75 | } |
||
76 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.