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 | View Code Duplication | class LinkUpdateObserver extends LinkObserver |
|
|
|||
35 | { |
||
36 | |||
37 | /** |
||
38 | * Initialize the product link with the passed attributes and returns an instance. |
||
39 | * |
||
40 | * @param array $attr The product link attributes |
||
41 | * |
||
42 | * @return array The initialized product link |
||
43 | */ |
||
44 | protected function initializeProductLink(array $attr) |
||
60 | |||
61 | /** |
||
62 | * Load's the link with the passed product/linked product/link type ID. |
||
63 | * |
||
64 | * @param integer $productId The product ID of the link to load |
||
65 | * @param integer $linkedProductId The linked product ID of the link to load |
||
66 | * @param integer $linkTypeId The link type ID of the product to load |
||
67 | * |
||
68 | * @return array The link |
||
69 | */ |
||
70 | protected function loadProductLink($productId, $linkedProductId, $linkTypeId) |
||
74 | } |
||
75 |
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.