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 |
||
30 | class Email extends CoreEmail |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * Plugin params. |
||
35 | * |
||
36 | * @var Data |
||
37 | */ |
||
38 | protected $_params; |
||
39 | |||
40 | /** |
||
41 | * Send user message when have success activation profile. |
||
42 | * |
||
43 | * @return array |
||
44 | */ |
||
45 | View Code Duplication | public function sendActivationMessage() |
|
54 | |||
55 | /** |
||
56 | * Send user create account profile message / set password. |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | View Code Duplication | public function sendCreateMessage() |
|
69 | |||
70 | /** |
||
71 | * Constructor hook method. |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | protected function _initialize() |
||
79 | |||
80 | /** |
||
81 | * Get from email - global settings. |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | protected function _getFromMail() |
||
89 | } |
||
90 |
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.