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 |
||
11 | abstract class WC_Stripe_Email_Failed_Authentication extends WC_Email { |
||
12 | /** |
||
13 | * An instance of the email, which would normally be sent after a failed payment. |
||
14 | * |
||
15 | * @var WC_Email |
||
16 | */ |
||
17 | public $original_email; |
||
18 | |||
19 | /** |
||
20 | * Generates the HTML for the email while keeping the `template_base` in mind. |
||
21 | * |
||
22 | * @return string |
||
23 | */ |
||
24 | View Code Duplication | public function get_content_html() { |
|
41 | |||
42 | /** |
||
43 | * Generates the plain text for the email while keeping the `template_base` in mind. |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | View Code Duplication | public function get_content_plain() { |
|
64 | |||
65 | /** |
||
66 | * Generates the URL, which will be used to authenticate the payment. |
||
67 | * |
||
68 | * @param WC_Order $order The order whose payment needs authentication. |
||
69 | * @return string |
||
70 | */ |
||
71 | public function get_authorization_url( $order ) { |
||
74 | |||
75 | /** |
||
76 | * Uses specific fields from `WC_Email_Customer_Invoice` for this email. |
||
77 | */ |
||
78 | public function init_form_fields() { |
||
95 | |||
96 | /** |
||
97 | * Triggers the email. |
||
98 | * |
||
99 | * @param WC_Order $order The renewal order whose payment failed. |
||
100 | */ |
||
101 | public function trigger( $order ) { |
||
126 | } |
||
127 |
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.