Conditions | 4 |
Paths | 4 |
Total Lines | 167 |
Code Lines | 118 |
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 'email-settings' : |
||
49 | $settings = array( |
||
50 | // Section 1: Email |
||
51 | array( |
||
52 | 'id' => 'give_title_email_settings_1', |
||
53 | 'type' => 'title' |
||
54 | ), |
||
55 | array( |
||
56 | 'id' => 'email_template', |
||
57 | 'name' => esc_html__( 'Email Template', 'give' ), |
||
58 | 'desc' => esc_html__( 'Choose a template. Click "Save Changes" then "Preview Donation Receipt" to see the new template.', 'give' ), |
||
59 | 'type' => 'select', |
||
60 | 'options' => give_get_email_templates() |
||
61 | ), |
||
62 | array( |
||
63 | 'id' => 'email_logo', |
||
64 | 'name' => esc_html__( 'Logo', 'give' ), |
||
65 | 'desc' => esc_html__( 'Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give' ), |
||
66 | 'type' => 'file' |
||
67 | ), |
||
68 | array( |
||
69 | 'id' => 'from_name', |
||
70 | 'name' => esc_html__( 'From Name', 'give' ), |
||
71 | 'desc' => esc_html__( 'The name which appears in the "From" field in donation receipt emails.', 'give' ), |
||
72 | 'default' => get_bloginfo( 'name' ), |
||
73 | 'type' => 'text' |
||
74 | ), |
||
75 | array( |
||
76 | 'id' => 'from_email', |
||
77 | 'name' => esc_html__( 'From Email', 'give' ), |
||
78 | 'desc' => esc_html__( 'Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'give' ), |
||
79 | 'default' => get_bloginfo( 'admin_email' ), |
||
80 | 'type' => 'text' |
||
81 | ), |
||
82 | array( |
||
83 | 'name' => esc_html__( 'Email Settings Docs Link', 'give' ), |
||
84 | 'id' => 'email_settings_docs_link', |
||
85 | 'url' => esc_url( 'http://docs.givewp.com/emailsettings' ), |
||
86 | 'title' => __( 'Email Settings', 'give' ), |
||
87 | 'type' => 'give_docs_link', |
||
88 | ), |
||
89 | array( |
||
90 | 'id' => 'give_title_email_settings_1', |
||
91 | 'type' => 'sectionend' |
||
92 | ) |
||
93 | ); |
||
94 | break; |
||
95 | |||
96 | case 'donation-receipt': |
||
97 | $settings = array( |
||
98 | // Section 2: donation. |
||
99 | array( |
||
100 | 'id' => 'give_title_email_settings_2', |
||
101 | 'type' => 'title' |
||
102 | ), |
||
103 | array( |
||
104 | 'id' => 'donation_subject', |
||
105 | 'name' => esc_html__( 'Donation Email Subject', 'give' ), |
||
106 | 'desc' => esc_html__( 'Enter the subject line for the donation receipt email.', 'give' ), |
||
107 | 'default' => esc_attr__( 'Donation Receipt', 'give' ), |
||
108 | 'type' => 'text' |
||
109 | ), |
||
110 | array( |
||
111 | 'id' => 'donation_receipt', |
||
112 | 'name' => esc_html__( 'Donation Receipt', 'give' ), |
||
113 | 'desc' => sprintf( |
||
114 | /* translators: %s: emails tags list */ |
||
115 | esc_html__( 'Enter the email that is sent to users after completing a successful donation. HTML is accepted. Available template tags: %s', 'give' ), |
||
116 | '<br/>'.give_get_emails_tags_list() |
||
117 | ), |
||
118 | 'type' => 'wysiwyg', |
||
119 | 'default' => give_get_default_donation_receipt_email() |
||
120 | ), |
||
121 | array( |
||
122 | 'name' => esc_html__( 'Donation Receipt Settings Docs Link', 'give' ), |
||
123 | 'id' => 'donation_receipt_settings_docs_link', |
||
124 | 'url' => esc_url( 'http://docs.givewp.com/donationreceipt' ), |
||
125 | 'title' => __( 'Donation Receipt Settings', 'give' ), |
||
126 | 'type' => 'give_docs_link', |
||
127 | ), |
||
128 | array( |
||
129 | 'id' => 'give_title_email_settings_2', |
||
130 | 'type' => 'sectionend' |
||
131 | ) |
||
132 | ); |
||
133 | break; |
||
134 | |||
135 | case 'new-donation-notification': |
||
136 | $settings = array( |
||
137 | // Section 3: New Donation. |
||
138 | array( |
||
139 | 'id' => 'give_title_email_settings_3', |
||
140 | 'type' => 'title' |
||
141 | ), |
||
142 | array( |
||
143 | 'id' => 'admin_notices', |
||
144 | 'name' => esc_html__( 'Admin Notifications', 'give' ), |
||
145 | 'desc' => esc_html__( 'Check this box if you do not want to receive emails when new donations are made.', 'give' ), |
||
146 | 'type' => 'radio_inline', |
||
147 | 'default' => 'enabled', |
||
148 | 'options' => array( |
||
149 | 'enabled' => __( 'Enabled', 'give' ), |
||
150 | 'disabled' => __( 'Disabled', 'give' ), |
||
151 | ) |
||
152 | ), |
||
153 | array( |
||
154 | 'id' => 'donation_notification_subject', |
||
155 | 'name' => esc_html__( 'Donation Notification Subject', 'give' ), |
||
156 | 'desc' => esc_html__( 'Enter the subject line for the donation notification email.', 'give' ), |
||
157 | 'type' => 'text', |
||
158 | 'default' => esc_attr__( 'New Donation - #{payment_id}', 'give' ) |
||
159 | ), |
||
160 | array( |
||
161 | 'id' => 'donation_notification', |
||
162 | 'name' => esc_html__( 'Donation Notification', 'give' ), |
||
163 | 'desc' => sprintf( |
||
164 | /* translators: %s: emails tags list */ |
||
165 | esc_html__( 'Enter the email that is sent to donation notification emails after completion of a donation. HTML is accepted. Available template tags: %s', 'give' ), |
||
166 | '<br/>'.give_get_emails_tags_list() |
||
167 | ), |
||
168 | 'type' => 'wysiwyg', |
||
169 | 'default' => give_get_default_donation_notification_email() |
||
170 | ), |
||
171 | array( |
||
172 | 'id' => 'admin_notice_emails', |
||
173 | 'name' => esc_html__( 'Donation Notification Emails', 'give' ), |
||
174 | 'desc' => __( 'Enter the email address(es) that should receive a notification anytime a donation is made, please only enter <span class="give-underline">one email address per line</span> and <strong>not separated by commas</strong>.', 'give' ), |
||
175 | 'type' => 'textarea', |
||
176 | 'default' => get_bloginfo( 'admin_email' ) |
||
177 | ), |
||
178 | array( |
||
179 | 'name' => esc_html__( 'Donation Notification Settings Docs Link', 'give' ), |
||
180 | 'id' => 'donation_notification_settings_docs_link', |
||
181 | 'url' => esc_url( 'http://docs.givewp.com/donationnotification' ), |
||
182 | 'title' => __( 'Donation Notification Settings', 'give' ), |
||
183 | 'type' => 'give_docs_link', |
||
184 | ), |
||
185 | array( |
||
186 | 'id' => 'give_title_email_settings_3', |
||
187 | 'type' => 'sectionend' |
||
188 | ) |
||
189 | ); |
||
190 | break; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * Filter the emails settings. |
||
195 | * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8 |
||
196 | */ |
||
197 | $settings = apply_filters( 'give_settings_emails', $settings ); |
||
198 | |||
199 | /** |
||
200 | * Filter the settings. |
||
201 | * |
||
202 | * @since 1.8 |
||
203 | * @param array $settings |
||
204 | */ |
||
205 | $settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
||
206 | |||
207 | // Output. |
||
208 | return $settings; |
||
209 | } |
||
210 | |||
231 |
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.