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 | class EeProductObserver extends ProductObserver |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Process the observer's business logic. |
||
40 | * |
||
41 | * @return array The processed row |
||
42 | */ |
||
43 | View Code Duplication | protected function process() |
|
53 | |||
54 | /** |
||
55 | * Prepare the attributes of the entity that has to be persisted. |
||
56 | * |
||
57 | * @return array The prepared attributes |
||
58 | */ |
||
59 | protected function prepareAttributes() |
||
75 | |||
76 | /** |
||
77 | * Set's the row ID of the product that has been created recently. |
||
78 | * |
||
79 | * @param string $rowId The row ID |
||
80 | * |
||
81 | * @return void |
||
82 | */ |
||
83 | protected function setLastRowId($rowId) |
||
87 | |||
88 | /** |
||
89 | * Return's the next available product entity ID. |
||
90 | * |
||
91 | * @return integer The next available product entity ID |
||
92 | */ |
||
93 | protected function nextIdentifier() |
||
97 | } |
||
98 |
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.