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 |
||
20 | class WC_Email_Customer_Reset_Password extends WC_Email { |
||
21 | |||
22 | /** |
||
23 | * User login name. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | public $user_login; |
||
28 | |||
29 | /** |
||
30 | * User email. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | public $user_email; |
||
35 | |||
36 | /** |
||
37 | * Reset key. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | public $reset_key; |
||
42 | |||
43 | /** |
||
44 | * Constructor. |
||
45 | */ |
||
46 | public function __construct() { |
||
65 | |||
66 | /** |
||
67 | * Trigger. |
||
68 | * |
||
69 | * @param string $user_login |
||
70 | * @param string $reset_key |
||
71 | */ |
||
72 | public function trigger( $user_login = '', $reset_key = '' ) { |
||
89 | |||
90 | /** |
||
91 | * Get content html. |
||
92 | * |
||
93 | * @access public |
||
94 | * @return string |
||
95 | */ |
||
96 | public function get_content_html() { |
||
107 | |||
108 | /** |
||
109 | * Get content plain. |
||
110 | * |
||
111 | * @access public |
||
112 | * @return string |
||
113 | */ |
||
114 | View Code Duplication | public function get_content_plain() { |
|
125 | } |
||
126 | |||
130 |
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.