Conditions | 4 |
Paths | 4 |
Total Lines | 182 |
Code Lines | 130 |
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 |
||
43 | public function get_settings() { |
||
44 | $settings = array(); |
||
45 | $current_section = give_get_current_setting_section(); |
||
46 | |||
47 | switch ( $current_section ) { |
||
48 | case 'paypal-standard': |
||
49 | $settings = array( |
||
50 | // Section 2: Paypal Standard. |
||
51 | array( |
||
52 | 'type' => 'title', |
||
53 | 'id' => 'give_title_gateway_settings_2', |
||
54 | ), |
||
55 | array( |
||
56 | 'name' => esc_html__( 'PayPal Email', 'give' ), |
||
57 | 'desc' => esc_html__( 'Enter your PayPal account\'s email.', 'give' ), |
||
58 | 'id' => 'paypal_email', |
||
59 | 'type' => 'email', |
||
60 | ), |
||
61 | array( |
||
62 | 'name' => esc_html__( 'PayPal Page Style', 'give' ), |
||
63 | 'desc' => esc_html__( 'Enter the name of the page style to use, or leave blank to use the default.', 'give' ), |
||
64 | 'id' => 'paypal_page_style', |
||
65 | 'type' => 'text', |
||
66 | ), |
||
67 | array( |
||
68 | 'name' => esc_html__( 'PayPal Transaction Type', 'give' ), |
||
69 | 'desc' => esc_html__( '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' ), |
||
70 | 'id' => 'paypal_button_type', |
||
71 | 'type' => 'radio_inline', |
||
72 | 'options' => array( |
||
73 | 'donation' => esc_html__( 'Donation', 'give' ), |
||
74 | 'standard' => esc_html__( 'Standard Transaction', 'give' ) |
||
75 | ), |
||
76 | 'default' => 'donation', |
||
77 | ), |
||
78 | array( |
||
79 | 'name' => esc_html__( 'PayPal IPN Verification', 'give' ), |
||
80 | 'desc' => esc_html__( 'If donations are not getting marked as complete, use a slightly less secure method of verifying donations.', 'give' ), |
||
81 | 'id' => 'paypal_verification', |
||
82 | 'type' => 'radio_inline', |
||
83 | 'default' => 'enabled', |
||
84 | 'options' => array( |
||
85 | 'enabled' => __( 'Enabled', 'give' ), |
||
86 | 'disabled' => __( 'Disabled', 'give' ), |
||
87 | ) |
||
88 | ), |
||
89 | array( |
||
90 | 'name' => esc_html__( 'PayPal Standard Gateway Settings Docs Link', 'give' ), |
||
91 | 'id' => 'paypal_standard_gateway_settings_docs_link', |
||
92 | 'url' => esc_url( 'http://docs.givewp.com/paypalstandard' ), |
||
93 | 'title' => __( 'PayPal Standard Gateway Settings', 'give' ), |
||
94 | 'type' => 'give_docs_link', |
||
95 | ), |
||
96 | array( |
||
97 | 'type' => 'sectionend', |
||
98 | 'id' => 'give_title_gateway_settings_2', |
||
99 | ) |
||
100 | ); |
||
101 | break; |
||
102 | |||
103 | case 'offline-donations' : |
||
104 | $settings = array( |
||
105 | // Section 3: Offline gateway. |
||
106 | array( |
||
107 | 'type' => 'title', |
||
108 | 'id' => 'give_title_gateway_settings_3', |
||
109 | ), |
||
110 | array( |
||
111 | 'name' => esc_html__( 'Collect Billing Details', 'give' ), |
||
112 | 'desc' => esc_html__( 'Enable to request billing details for offline donations. Will appear above offline donation instructions. Can be enabled/disabled per form.', 'give' ), |
||
113 | 'id' => 'give_offline_donation_enable_billing_fields', |
||
114 | 'type' => 'radio_inline', |
||
115 | 'default' => 'disabled', |
||
116 | 'options' => array( |
||
117 | 'enabled' => __( 'Enabled', 'give' ), |
||
118 | 'disabled' => __( 'Disabled', 'give' ) |
||
119 | ) |
||
120 | ), |
||
121 | array( |
||
122 | 'name' => esc_html__( 'Offline Donation Instructions', 'give' ), |
||
123 | 'desc' => esc_html__( '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' ), |
||
124 | 'id' => 'global_offline_donation_content', |
||
125 | 'default' => give_get_default_offline_donation_content(), |
||
126 | 'type' => 'wysiwyg', |
||
127 | 'options' => array( |
||
128 | 'textarea_rows' => 6, |
||
129 | ) |
||
130 | ), |
||
131 | array( |
||
132 | 'name' => esc_html__( 'Offline Donation Email Instructions Subject', 'give' ), |
||
133 | 'desc' => esc_html__( 'Enter the subject line for the donation receipt email.', 'give' ), |
||
134 | 'id' => 'offline_donation_subject', |
||
135 | 'default' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ), |
||
136 | 'type' => 'text' |
||
137 | ), |
||
138 | array( |
||
139 | 'name' => esc_html__( 'Offline Donation Email Instructions', 'give' ), |
||
140 | 'desc' => esc_html__( 'Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ), |
||
141 | 'id' => 'global_offline_donation_email', |
||
142 | 'default' => give_get_default_offline_donation_email_content(), |
||
143 | 'type' => 'wysiwyg', |
||
144 | 'options' => array( |
||
145 | 'textarea_rows' => 6, |
||
146 | ) |
||
147 | ), |
||
148 | array( |
||
149 | 'name' => esc_html__( 'Offline Donations Settings Docs Link', 'give' ), |
||
150 | 'id' => 'offline_gateway_settings_docs_link', |
||
151 | 'url' => esc_url( 'http://docs.givewp.com/offlinegateway' ), |
||
152 | 'title' => __( 'Offline Gateway Settings', 'give' ), |
||
153 | 'type' => 'give_docs_link', |
||
154 | ), |
||
155 | array( |
||
156 | 'type' => 'sectionend', |
||
157 | 'id' => 'give_title_gateway_settings_3', |
||
158 | ) |
||
159 | ); |
||
160 | break; |
||
161 | |||
162 | case 'gateways-settings': |
||
163 | $settings = array( |
||
164 | // Section 1: Gateways. |
||
165 | array( |
||
166 | 'id' => 'give_title_gateway_settings_1', |
||
167 | 'type' => 'title' |
||
168 | ), |
||
169 | array( |
||
170 | 'name' => esc_html__( 'Test Mode', 'give' ), |
||
171 | 'desc' => esc_html__( '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' ), |
||
172 | 'id' => 'test_mode', |
||
173 | 'type' => 'radio_inline', |
||
174 | 'default' => 'disabled', |
||
175 | 'options' => array( |
||
176 | 'enabled' => __( 'Enabled', 'give' ), |
||
177 | 'disabled' => __( 'Disabled', 'give' ), |
||
178 | ) |
||
179 | ), |
||
180 | array( |
||
181 | 'name' => esc_html__( 'Enabled Gateways', 'give' ), |
||
182 | 'desc' => esc_html__( 'Enable your payment gateway. Can be ordered by dragging.', 'give' ), |
||
183 | 'id' => 'gateways', |
||
184 | 'type' => 'enabled_gateways' |
||
185 | ), |
||
186 | array( |
||
187 | 'name' => esc_html__( 'Default Gateway', 'give' ), |
||
188 | 'desc' => esc_html__( 'The gateway that will be selected by default.', 'give' ), |
||
189 | 'id' => 'default_gateway', |
||
190 | 'type' => 'default_gateway' |
||
191 | ), |
||
192 | array( |
||
193 | 'name' => esc_html__( 'Gateways Docs Link', 'give' ), |
||
194 | 'id' => 'gateway_settings_docs_link', |
||
195 | 'url' => esc_url( 'http://docs.givewp.com/gatewayssettings' ), |
||
196 | 'title' => __( 'Gateway Settings', 'give' ), |
||
197 | 'type' => 'give_docs_link', |
||
198 | ), |
||
199 | array( |
||
200 | 'id' => 'give_title_gateway_settings_1', |
||
201 | 'type' => 'sectionend' |
||
202 | ), |
||
203 | ); |
||
204 | break; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * Filter the payment gateways settings. |
||
209 | * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8 |
||
210 | */ |
||
211 | $settings = apply_filters( 'give_settings_gateways', $settings ); |
||
212 | |||
213 | /** |
||
214 | * Filter the settings. |
||
215 | * |
||
216 | * @since 1.8 |
||
217 | * |
||
218 | * @param array $settings |
||
219 | */ |
||
220 | $settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
||
221 | |||
222 | // Output. |
||
223 | return $settings; |
||
224 | } |
||
225 | |||
246 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.