Conditions | 4 |
Paths | 4 |
Total Lines | 208 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
49 | public function get_settings() { |
||
50 | $settings = array(); |
||
51 | $current_section = give_get_current_setting_section(); |
||
52 | |||
53 | switch ( $current_section ) { |
||
54 | case 'paypal-standard': |
||
55 | $settings = array( |
||
56 | // Section 2: PayPal Standard. |
||
57 | array( |
||
58 | 'type' => 'title', |
||
59 | 'id' => 'give_title_gateway_settings_2', |
||
60 | ), |
||
61 | array( |
||
62 | 'name' => __( 'PayPal Email', 'give' ), |
||
63 | 'desc' => __( 'Enter your PayPal account\'s email.', 'give' ), |
||
64 | 'id' => 'paypal_email', |
||
65 | 'type' => 'email', |
||
66 | ), |
||
67 | array( |
||
68 | 'name' => __( 'PayPal Page Style', 'give' ), |
||
69 | 'desc' => __( 'Enter the name of the PayPal page style to use, or leave blank to use the default.', 'give' ), |
||
70 | 'id' => 'paypal_page_style', |
||
71 | 'type' => 'text', |
||
72 | ), |
||
73 | array( |
||
74 | 'name' => __( 'PayPal Transaction Type', 'give' ), |
||
75 | 'desc' => __( 'Nonprofits must verify their status to withdraw donations they receive via PayPal. PayPal users that are not verified nonprofits must demonstrate how their donations will be used, once they raise more than $10,000. By default, Give transactions are sent to PayPal as donations. You may change the transaction type using this option if you feel you may not meet PayPal\'s donation requirements.', 'give' ), |
||
76 | 'id' => 'paypal_button_type', |
||
77 | 'type' => 'radio_inline', |
||
78 | 'options' => array( |
||
79 | 'donation' => __( 'Donation', 'give' ), |
||
80 | 'standard' => __( 'Standard Transaction', 'give' ) |
||
81 | ), |
||
82 | 'default' => 'donation', |
||
83 | ), |
||
84 | array( |
||
85 | 'name' => __( 'Billing Details', 'give' ), |
||
86 | 'desc' => __( 'This option will enable the billing details section for PayPal Standard which requires the donor\'s address to complete the donation. These fields are not required by PayPal to process the transaction, but you may have a need to collect the data.', 'give' ), |
||
87 | 'id' => 'paypal_standard_billing_details', |
||
88 | 'type' => 'radio_inline', |
||
89 | 'default' => 'disabled', |
||
90 | 'options' => array( |
||
91 | 'enabled' => __( 'Enabled', 'give' ), |
||
92 | 'disabled' => __( 'Disabled', 'give' ), |
||
93 | ) |
||
94 | ), |
||
95 | array( |
||
96 | 'name' => __( 'PayPal IPN Verification', 'give' ), |
||
97 | 'desc' => __( 'If donations are not getting marked as complete, use a slightly less secure method of verifying donations.', 'give' ), |
||
98 | 'id' => 'paypal_verification', |
||
99 | 'type' => 'radio_inline', |
||
100 | 'default' => 'enabled', |
||
101 | 'options' => array( |
||
102 | 'enabled' => __( 'Enabled', 'give' ), |
||
103 | 'disabled' => __( 'Disabled', 'give' ), |
||
104 | ) |
||
105 | ), |
||
106 | array( |
||
107 | 'id' => 'paypal_invoice_prefix', |
||
108 | 'name' => esc_html__( 'Invoice ID Prefix', 'give' ), |
||
109 | 'desc' => esc_html__( 'Please enter a prefix for your invoice numbers. If you use your PayPal account for multiple stores ensure this prefix is unique as PayPal will not allow orders with the same invoice number.', 'give' ), |
||
110 | 'type' => 'text', |
||
111 | 'default' => 'GIVE-', |
||
112 | ), |
||
113 | array( |
||
114 | 'name' => __( 'PayPal Standard Gateway Settings Docs Link', 'give' ), |
||
115 | 'id' => 'paypal_standard_gateway_settings_docs_link', |
||
116 | 'url' => esc_url( 'http://docs.givewp.com/settings-gateway-paypal-standard' ), |
||
117 | 'title' => __( 'PayPal Standard Gateway Settings', 'give' ), |
||
118 | 'type' => 'give_docs_link', |
||
119 | ), |
||
120 | array( |
||
121 | 'type' => 'sectionend', |
||
122 | 'id' => 'give_title_gateway_settings_2', |
||
123 | ) |
||
124 | ); |
||
125 | break; |
||
126 | |||
127 | case 'offline-donations' : |
||
128 | $settings = array( |
||
129 | // Section 3: Offline gateway. |
||
130 | array( |
||
131 | 'type' => 'title', |
||
132 | 'id' => 'give_title_gateway_settings_3', |
||
133 | ), |
||
134 | array( |
||
135 | 'name' => __( 'Collect Billing Details', 'give' ), |
||
136 | 'desc' => __( 'Enable to request billing details for offline donations. Will appear above offline donation instructions. Can be enabled/disabled per form.', 'give' ), |
||
137 | 'id' => 'give_offline_donation_enable_billing_fields', |
||
138 | 'type' => 'radio_inline', |
||
139 | 'default' => 'disabled', |
||
140 | 'options' => array( |
||
141 | 'enabled' => __( 'Enabled', 'give' ), |
||
142 | 'disabled' => __( 'Disabled', 'give' ) |
||
143 | ) |
||
144 | ), |
||
145 | array( |
||
146 | 'name' => __( 'Offline Donation Instructions', 'give' ), |
||
147 | 'desc' => __( 'The following content will appear for all forms when the user selects the offline donation payment option. Note: You may customize the content per form as needed.', 'give' ), |
||
148 | 'id' => 'global_offline_donation_content', |
||
149 | 'default' => give_get_default_offline_donation_content(), |
||
150 | 'type' => 'wysiwyg', |
||
151 | 'options' => array( |
||
152 | 'textarea_rows' => 6, |
||
153 | ) |
||
154 | ), |
||
155 | array( |
||
156 | 'name' => esc_html__( 'Offline Donations Settings Docs Link', 'give' ), |
||
157 | 'id' => 'offline_gateway_settings_docs_link', |
||
158 | 'url' => esc_url( 'http://docs.givewp.com/offlinegateway' ), |
||
159 | 'title' => __( 'Offline Gateway Settings', 'give' ), |
||
160 | 'type' => 'give_docs_link', |
||
161 | ), |
||
162 | array( |
||
163 | 'type' => 'sectionend', |
||
164 | 'id' => 'give_title_gateway_settings_3', |
||
165 | ) |
||
166 | ); |
||
167 | break; |
||
168 | |||
169 | case 'gateways-settings': |
||
170 | $settings = array( |
||
171 | // Section 1: Gateways. |
||
172 | array( |
||
173 | 'id' => 'give_title_gateway_settings_1', |
||
174 | 'type' => 'title' |
||
175 | ), |
||
176 | array( |
||
177 | 'id' => 'gateway_notice', |
||
178 | 'type' => 'gateway_notice', |
||
179 | ), |
||
180 | array( |
||
181 | 'name' => __( 'Test Mode', 'give' ), |
||
182 | 'desc' => __( 'While in test mode no live donations are processed. To fully use test mode, you must have a sandbox (test) account for the payment gateway you are testing.', 'give' ), |
||
183 | 'id' => 'test_mode', |
||
184 | 'type' => 'radio_inline', |
||
185 | 'default' => 'disabled', |
||
186 | 'options' => array( |
||
187 | 'enabled' => __( 'Enabled', 'give' ), |
||
188 | 'disabled' => __( 'Disabled', 'give' ), |
||
189 | ) |
||
190 | ), |
||
191 | array( |
||
192 | 'name' => __( 'Enabled Gateways', 'give' ), |
||
193 | 'desc' => __( 'Enable your payment gateway. Can be ordered by dragging.', 'give' ), |
||
194 | 'id' => 'gateways', |
||
195 | 'type' => 'enabled_gateways' |
||
196 | ), |
||
197 | |||
198 | /** |
||
199 | * "Enabled Gateways" setting field contains gateways label setting but when you save gateway settings then label will not save |
||
200 | * because this is not registered setting API and code will not recognize them. |
||
201 | * |
||
202 | * This setting will not render on admin setting screen but help internal code to recognize "gateways_label" setting and add them to give setting when save. |
||
203 | */ |
||
204 | array( |
||
205 | 'name' => __( 'Gateways Label', 'give' ), |
||
206 | 'desc' => '', |
||
207 | 'id' => 'gateways_label', |
||
208 | 'type' => 'gateways_label_hidden' |
||
209 | ), |
||
210 | |||
211 | /** |
||
212 | * "Enabled Gateways" setting field contains default gateway setting but when you save gateway settings then this setting will not save |
||
213 | * because this is not registered setting API and code will not recognize them. |
||
214 | * |
||
215 | * This setting will not render on admin setting screen but help internal code to recognize "default_gateway" setting and add them to give setting when save. |
||
216 | */ |
||
217 | array( |
||
218 | 'name' => __( 'Default Gateway', 'give' ), |
||
219 | 'desc' => __( 'The gateway that will be selected by default.', 'give' ), |
||
220 | 'id' => 'default_gateway', |
||
221 | 'type' => 'default_gateway_hidden' |
||
222 | ), |
||
223 | |||
224 | array( |
||
225 | 'name' => __( 'Gateways Docs Link', 'give' ), |
||
226 | 'id' => 'gateway_settings_docs_link', |
||
227 | 'url' => esc_url( 'http://docs.givewp.com/settings-gateways' ), |
||
228 | 'title' => __( 'Gateway Settings', 'give' ), |
||
229 | 'type' => 'give_docs_link', |
||
230 | ), |
||
231 | array( |
||
232 | 'id' => 'give_title_gateway_settings_1', |
||
233 | 'type' => 'sectionend' |
||
234 | ), |
||
235 | ); |
||
236 | break; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Filter the payment gateways settings. |
||
241 | * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8 |
||
242 | */ |
||
243 | $settings = apply_filters( 'give_settings_gateways', $settings ); |
||
244 | |||
245 | /** |
||
246 | * Filter the settings. |
||
247 | * |
||
248 | * @since 1.8 |
||
249 | * |
||
250 | * @param array $settings |
||
251 | */ |
||
252 | $settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
||
253 | |||
254 | // Output. |
||
255 | return $settings; |
||
256 | } |
||
257 | |||
415 |
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.