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 |
||
13 | class WC_Payment_Gateway_eCheck extends WC_Payment_Gateway { |
||
14 | |||
15 | /** |
||
16 | * Builds our payment fields area - including tokenization fields for logged |
||
17 | * in users, and the actual payment fields. |
||
18 | * @since 2.6.0 |
||
19 | */ |
||
20 | View Code Duplication | public function payment_fields() { |
|
|
|||
21 | if ( $this->supports( 'tokenization' ) && is_checkout() && is_user_logged_in() ) { |
||
22 | $this->tokenization_script(); |
||
23 | $this->saved_payment_methods(); |
||
24 | $this->form(); |
||
25 | $this->save_payment_method_checkbox(); |
||
26 | } else { |
||
27 | $this->form(); |
||
28 | } |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Outputs fields for entering eCheck information. |
||
33 | * @since 2.6.0 |
||
34 | */ |
||
35 | public function form() { |
||
63 | |||
64 | } |
||
65 |
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.