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 | View Code Duplication | class WC_Gateway_Stripe_Giropay extends WC_Stripe_Payment_Gateway { |
|
|
|||
14 | /** |
||
15 | * Notices (array) |
||
16 | * @var array |
||
17 | */ |
||
18 | public $notices = array(); |
||
19 | |||
20 | /** |
||
21 | * Is test mode active? |
||
22 | * |
||
23 | * @var bool |
||
24 | */ |
||
25 | public $testmode; |
||
26 | |||
27 | /** |
||
28 | * Alternate credit card statement name |
||
29 | * |
||
30 | * @var bool |
||
31 | */ |
||
32 | public $statement_descriptor; |
||
33 | |||
34 | /** |
||
35 | * API access secret key |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | public $secret_key; |
||
40 | |||
41 | /** |
||
42 | * Api access publishable key |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | public $publishable_key; |
||
47 | |||
48 | /** |
||
49 | * Should we store the users credit cards? |
||
50 | * |
||
51 | * @var bool |
||
52 | */ |
||
53 | public $saved_cards; |
||
54 | |||
55 | /** |
||
56 | * Constructor |
||
57 | */ |
||
58 | public function __construct() { |
||
92 | |||
93 | /** |
||
94 | * Returns all supported currencies for this payment method. |
||
95 | * |
||
96 | * @since 4.0.0 |
||
97 | * @version 4.0.0 |
||
98 | * @return array |
||
99 | */ |
||
100 | public function get_supported_currency() { |
||
108 | |||
109 | /** |
||
110 | * Checks to see if all criteria is met before showing payment method. |
||
111 | * |
||
112 | * @since 4.0.0 |
||
113 | * @version 4.0.0 |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function is_available() { |
||
123 | |||
124 | /** |
||
125 | * Get_icon function. |
||
126 | * |
||
127 | * @since 1.0.0 |
||
128 | * @version 4.0.0 |
||
129 | * @return string |
||
130 | */ |
||
131 | public function get_icon() { |
||
132 | $icons = $this->payment_icons(); |
||
133 | |||
134 | $icons_str = ''; |
||
135 | |||
136 | $icons_str .= isset( $icons['giropay'] ) ? $icons['giropay'] : ''; |
||
137 | |||
138 | return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * payment_scripts function. |
||
143 | * |
||
144 | * Outputs scripts used for stripe payment |
||
145 | * |
||
146 | * @access public |
||
147 | */ |
||
148 | public function payment_scripts() { |
||
156 | |||
157 | /** |
||
158 | * Initialize Gateway Settings Form Fields. |
||
159 | */ |
||
160 | public function init_form_fields() { |
||
163 | |||
164 | /** |
||
165 | * Payment form on checkout page |
||
166 | */ |
||
167 | public function payment_fields() { |
||
197 | |||
198 | /** |
||
199 | * Creates the source for charge. |
||
200 | * |
||
201 | * @since 4.0.0 |
||
202 | * @version 4.0.0 |
||
203 | * @param object $order |
||
204 | * @return mixed |
||
205 | */ |
||
206 | public function create_source( $order ) { |
||
224 | |||
225 | /** |
||
226 | * Process the payment |
||
227 | * |
||
228 | * @param int $order_id Reference. |
||
229 | * @param bool $retry Should we retry on fail. |
||
230 | * @param bool $force_save_source Force payment source to be saved. |
||
231 | * |
||
232 | * @throws Exception If payment will not be accepted. |
||
233 | * |
||
234 | * @return array|void |
||
235 | */ |
||
236 | public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
||
285 | } |
||
286 |
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.