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 | class WC_Stripe_Email_Failed_Renewal_Authentication extends WC_Stripe_Email_Failed_Authentication { |
||
12 | /** |
||
13 | * Constructor. |
||
14 | * |
||
15 | * @param WC_Email[] $email_classes All existing instances of WooCommerce emails. |
||
16 | */ |
||
17 | View Code Duplication | public function __construct( $email_classes = array() ) { |
|
37 | |||
38 | /** |
||
39 | * Triggers the email while also disconnecting the original Subscriptions email. |
||
40 | * |
||
41 | * @param WC_Order $order The order that is being paid. |
||
42 | */ |
||
43 | public function trigger( $order ) { |
||
60 | |||
61 | /** |
||
62 | * Returns the default subject of the email (modifyable in settings). |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | public function get_default_subject() { |
||
69 | |||
70 | /** |
||
71 | * Returns the default heading of the email (modifyable in settings). |
||
72 | * |
||
73 | * @return string |
||
74 | */ |
||
75 | public function get_default_heading() { |
||
78 | |||
79 | /** |
||
80 | * Prevent all customer-facing retry notifications from being sent after this email. |
||
81 | * |
||
82 | * @param array $rule_array The raw details about the retry rule. |
||
83 | * @param int $retry_number The number of the retry. |
||
84 | * @param int $order_id The ID of the order that needs payment. |
||
85 | * @return array |
||
86 | */ |
||
87 | public function prevent_retry_notification_email( $rule_array, $retry_number, $order_id ) { |
||
94 | |||
95 | /** |
||
96 | * Send store owner a different email when the retry is related to an authentication required error. |
||
97 | * |
||
98 | * @param array $rule_array The raw details about the retry rule. |
||
99 | * @param int $retry_number The number of the retry. |
||
100 | * @param int $order_id The ID of the order that needs payment. |
||
101 | * @return array |
||
102 | */ |
||
103 | public function set_store_owner_custom_email( $rule_array, $retry_number, $order_id ) { |
||
113 | } |
||
114 |
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.