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 |
||
34 | class LinkAttributePositionUpdateObserver extends LinkAttributePositionObserver |
||
35 | { |
||
36 | |||
37 | /** |
||
38 | * Initialize the product link attribute with the passed attributes and returns an instance. |
||
39 | * |
||
40 | * @param array $attr The product link attribute |
||
41 | * |
||
42 | * @return array The initialized product link attribute |
||
43 | */ |
||
44 | View Code Duplication | protected function initializeProductLinkAttributeInt(array $attr) |
|
59 | |||
60 | /** |
||
61 | * Initialize the product link attribute with the passed attributes and returns an instance. |
||
62 | * |
||
63 | * @param array $attr The product link attribute |
||
64 | * |
||
65 | * @return array The initialized product link attribute |
||
66 | */ |
||
67 | View Code Duplication | protected function initializeProductLinkAttributeDecimal(array $attr) |
|
82 | |||
83 | /** |
||
84 | * Initialize the product link attribute with the passed attributes and returns an instance. |
||
85 | * |
||
86 | * @param array $attr The product link attribute |
||
87 | * |
||
88 | * @return array The initialized product link attribute |
||
89 | */ |
||
90 | View Code Duplication | protected function initializeProductLinkAttributeVarchar(array $attr) |
|
105 | |||
106 | /** |
||
107 | * Return's the product link attribute integer value with the passed product link attribute/link ID. |
||
108 | * |
||
109 | * @param integer $productLinkAttributeId The product link attribute ID of the attributes |
||
110 | * @param integer $linkId The link ID of the attribute |
||
111 | * |
||
112 | * @return array The product link attribute integer value |
||
113 | */ |
||
114 | protected function loadProductLinkAttributeInt($productLinkAttributeId, $linkId) |
||
118 | |||
119 | /** |
||
120 | * Return's the product link attribute decimal value with the passed product link attribute/link ID. |
||
121 | * |
||
122 | * @param integer $productLinkAttributeId The product link attribute ID of the attributes |
||
123 | * @param integer $linkId The link ID of the attribute |
||
124 | * |
||
125 | * @return array The product link attribute decimal value |
||
126 | */ |
||
127 | protected function loadProductLinkAttributeDecimal($productLinkAttributeId, $linkId) |
||
131 | |||
132 | /** |
||
133 | * Return's the product link attribute varchar value with the passed product link attribute/link ID. |
||
134 | * |
||
135 | * @param integer $productLinkAttributeId The product link attribute ID of the attributes |
||
136 | * @param integer $linkId The link ID of the attribute |
||
137 | * |
||
138 | * @return array The product link attribute varchar value |
||
139 | */ |
||
140 | protected function loadProductLinkAttributeVarchar($productLinkAttributeId, $linkId) |
||
144 | } |
||
145 |
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.