| Conditions | 34 |
| Paths | 12104 |
| Total Lines | 236 |
| Code Lines | 179 |
| Lines | 184 |
| Ratio | 77.97 % |
| 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 |
||
| 124 | function _give_register_admin_notices() { |
||
| 125 | // Bailout. |
||
| 126 | if( ! is_admin() ) { |
||
| 127 | return; |
||
| 128 | } |
||
| 129 | |||
| 130 | // Add payment bulk notice. |
||
| 131 | if ( |
||
| 132 | current_user_can( 'edit_give_payments' ) |
||
| 133 | && isset( $_GET['action'] ) |
||
| 134 | && ! empty( $_GET['action'] ) |
||
| 135 | && isset( $_GET['payment'] ) |
||
| 136 | && ! empty( $_GET['payment'] ) |
||
| 137 | ) { |
||
| 138 | $payment_count = isset( $_GET['payment'] ) ? count( $_GET['payment'] ) : 0; |
||
| 139 | |||
| 140 | switch ( $_GET['action'] ) { |
||
| 141 | View Code Duplication | case 'delete': |
|
| 142 | Give()->notices->register_notice( array( |
||
| 143 | 'id' => 'bulk_action_delete', |
||
| 144 | 'type' => 'updated', |
||
| 145 | 'description' => sprintf( |
||
| 146 | _n( |
||
| 147 | 'Successfully deleted one transaction.', |
||
| 148 | 'Successfully deleted %d transactions.', |
||
| 149 | $payment_count, |
||
| 150 | 'give' |
||
| 151 | ), |
||
| 152 | $payment_count ), |
||
| 153 | 'show' => true, |
||
| 154 | ) ); |
||
| 155 | |||
| 156 | break; |
||
| 157 | |||
| 158 | View Code Duplication | case 'resend-receipt': |
|
| 159 | Give()->notices->register_notice( array( |
||
| 160 | 'id' => 'bulk_action_resend_receipt', |
||
| 161 | 'type' => 'updated', |
||
| 162 | 'description' => sprintf( |
||
| 163 | _n( |
||
| 164 | 'Successfully sent email receipt to one recipient.', |
||
| 165 | 'Successfully sent email receipts to %d recipients.', |
||
| 166 | $payment_count, |
||
| 167 | 'give' |
||
| 168 | ), |
||
| 169 | $payment_count |
||
| 170 | ), |
||
| 171 | 'show' => true, |
||
| 172 | ) ); |
||
| 173 | break; |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | // Add give message notices. |
||
| 178 | if ( ! empty( $_GET['give-message'] ) ) { |
||
| 179 | // Donation reports errors. |
||
| 180 | if ( current_user_can( 'view_give_reports' ) ) { |
||
| 181 | switch ( $_GET['give-message'] ) { |
||
| 182 | View Code Duplication | case 'donation_deleted' : |
|
| 183 | Give()->notices->register_notice( array( |
||
| 184 | 'id' => 'give-donation-deleted', |
||
| 185 | 'type' => 'updated', |
||
| 186 | 'description' => __( 'The donation has been deleted.', 'give' ), |
||
| 187 | 'show' => true, |
||
| 188 | ) ); |
||
| 189 | break; |
||
| 190 | View Code Duplication | case 'email_sent' : |
|
| 191 | Give()->notices->register_notice( array( |
||
| 192 | 'id' => 'give-payment-sent', |
||
| 193 | 'type' => 'updated', |
||
| 194 | 'description' => __( 'The donation receipt has been resent.', 'give' ), |
||
| 195 | 'show' => true, |
||
| 196 | ) ); |
||
| 197 | break; |
||
| 198 | View Code Duplication | case 'refreshed-reports' : |
|
| 199 | Give()->notices->register_notice( array( |
||
| 200 | 'id' => 'give-refreshed-reports', |
||
| 201 | 'type' => 'updated', |
||
| 202 | 'description' => __( 'The reports cache has been cleared.', 'give' ), |
||
| 203 | 'show' => true, |
||
| 204 | ) ); |
||
| 205 | break; |
||
| 206 | View Code Duplication | case 'donation-note-deleted' : |
|
| 207 | Give()->notices->register_notice( array( |
||
| 208 | 'id' => 'give-donation-note-deleted', |
||
| 209 | 'type' => 'updated', |
||
| 210 | 'description' => __( 'The donation note has been deleted.', 'give' ), |
||
| 211 | 'show' => true, |
||
| 212 | ) ); |
||
| 213 | break; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | // Give settings notices and errors. |
||
| 218 | if ( current_user_can( 'manage_give_settings' ) ) { |
||
| 219 | switch ( $_GET['give-message'] ) { |
||
| 220 | View Code Duplication | case 'settings-imported' : |
|
| 221 | Give()->notices->register_notice( array( |
||
| 222 | 'id' => 'give-settings-imported', |
||
| 223 | 'type' => 'updated', |
||
| 224 | 'description' => __( 'The settings have been imported.', 'give' ), |
||
| 225 | 'show' => true, |
||
| 226 | ) ); |
||
| 227 | break; |
||
| 228 | View Code Duplication | case 'api-key-generated' : |
|
| 229 | Give()->notices->register_notice( array( |
||
| 230 | 'id' => 'give-api-key-generated', |
||
| 231 | 'type' => 'updated', |
||
| 232 | 'description' => __( 'API keys have been generated.', 'give' ), |
||
| 233 | 'show' => true, |
||
| 234 | ) ); |
||
| 235 | break; |
||
| 236 | View Code Duplication | case 'api-key-exists' : |
|
| 237 | Give()->notices->register_notice( array( |
||
| 238 | 'id' => 'give-api-key-exists', |
||
| 239 | 'type' => 'updated', |
||
| 240 | 'description' => __( 'The specified user already has API keys.', 'give' ), |
||
| 241 | 'show' => true, |
||
| 242 | ) ); |
||
| 243 | break; |
||
| 244 | View Code Duplication | case 'api-key-regenerated' : |
|
| 245 | Give()->notices->register_notice( array( |
||
| 246 | 'id' => 'give-api-key-regenerated', |
||
| 247 | 'type' => 'updated', |
||
| 248 | 'description' => __( 'API keys have been regenerated.', 'give' ), |
||
| 249 | 'show' => true, |
||
| 250 | ) ); |
||
| 251 | break; |
||
| 252 | View Code Duplication | case 'api-key-revoked' : |
|
| 253 | Give()->notices->register_notice( array( |
||
| 254 | 'id' => 'give-api-key-revoked', |
||
| 255 | 'type' => 'updated', |
||
| 256 | 'description' => __( 'API keys have been revoked.', 'give' ), |
||
| 257 | 'show' => true, |
||
| 258 | ) ); |
||
| 259 | break; |
||
| 260 | View Code Duplication | case 'sent-test-email' : |
|
| 261 | Give()->notices->register_notice( array( |
||
| 262 | 'id' => 'give-sent-test-email', |
||
| 263 | 'type' => 'updated', |
||
| 264 | 'description' => __( 'The test email has been sent.', 'give' ), |
||
| 265 | 'show' => true, |
||
| 266 | ) ); |
||
| 267 | break; |
||
| 268 | View Code Duplication | case 'matched-success-failure-page': |
|
| 269 | Give()->notices->register_notice( array( |
||
| 270 | 'id' => 'give-matched-success-failure-page', |
||
| 271 | 'type' => 'updated', |
||
| 272 | 'description' => __( 'You cannot set the success and failed pages to the same page', 'give' ), |
||
| 273 | 'show' => true, |
||
| 274 | ) ); |
||
| 275 | break; |
||
| 276 | } |
||
| 277 | } |
||
| 278 | // Payments errors. |
||
| 279 | if ( current_user_can( 'edit_give_payments' ) ) { |
||
| 280 | switch ( $_GET['give-message'] ) { |
||
| 281 | View Code Duplication | case 'note-added' : |
|
| 282 | Give()->notices->register_notice( array( |
||
| 283 | 'id' => 'give-note-added', |
||
| 284 | 'type' => 'updated', |
||
| 285 | 'description' => __( 'The donation note has been added.', 'give' ), |
||
| 286 | 'show' => true, |
||
| 287 | ) ); |
||
| 288 | break; |
||
| 289 | View Code Duplication | case 'payment-updated' : |
|
| 290 | Give()->notices->register_notice( array( |
||
| 291 | 'id' => 'give-payment-updated', |
||
| 292 | 'type' => 'updated', |
||
| 293 | 'description' => __( 'The donation has been updated.', 'give' ), |
||
| 294 | 'show' => true, |
||
| 295 | ) ); |
||
| 296 | break; |
||
| 297 | } |
||
| 298 | } |
||
| 299 | |||
| 300 | // Donor Notices. |
||
| 301 | if ( current_user_can( 'edit_give_payments' ) ) { |
||
| 302 | switch ( $_GET['give-message'] ) { |
||
| 303 | View Code Duplication | case 'donor-deleted' : |
|
| 304 | Give()->notices->register_notice( array( |
||
| 305 | 'id' => 'give-donor-deleted', |
||
| 306 | 'type' => 'updated', |
||
| 307 | 'description' => __( 'The donor has been deleted.', 'give' ), |
||
| 308 | 'show' => true, |
||
| 309 | ) ); |
||
| 310 | break; |
||
| 311 | |||
| 312 | View Code Duplication | case 'email-added' : |
|
| 313 | Give()->notices->register_notice( array( |
||
| 314 | 'id' => 'give-donor-email-added', |
||
| 315 | 'type' => 'updated', |
||
| 316 | 'description' => __( 'Donor email added.', 'give' ), |
||
| 317 | 'show' => true, |
||
| 318 | ) ); |
||
| 319 | break; |
||
| 320 | |||
| 321 | View Code Duplication | case 'email-removed' : |
|
| 322 | Give()->notices->register_notice( array( |
||
| 323 | 'id' => 'give-donor-email-removed', |
||
| 324 | 'type' => 'updated', |
||
| 325 | 'description' => __( 'Donor email removed.', 'give' ), |
||
| 326 | 'show' => true, |
||
| 327 | ) ); |
||
| 328 | break; |
||
| 329 | |||
| 330 | View Code Duplication | case 'email-remove-failed' : |
|
| 331 | Give()->notices->register_notice( array( |
||
| 332 | 'id' => 'give-donor-email-remove-failed', |
||
| 333 | 'type' => 'updated', |
||
| 334 | 'description' => __( 'Failed to remove donor email.', 'give' ), |
||
| 335 | 'show' => true, |
||
| 336 | ) ); |
||
| 337 | break; |
||
| 338 | |||
| 339 | View Code Duplication | case 'primary-email-updated' : |
|
| 340 | Give()->notices->register_notice( array( |
||
| 341 | 'id' => 'give-donor-primary-email-updated', |
||
| 342 | 'type' => 'updated', |
||
| 343 | 'description' => __( 'Primary email updated for donor.', 'give' ), |
||
| 344 | 'show' => true, |
||
| 345 | ) ); |
||
| 346 | break; |
||
| 347 | |||
| 348 | View Code Duplication | case 'primary-email-failed' : |
|
| 349 | Give()->notices->register_notice( array( |
||
| 350 | 'id' => 'give-donor-primary-email-failed', |
||
| 351 | 'type' => 'updated', |
||
| 352 | 'description' => __( 'Failed to set primary email.', 'give' ), |
||
| 353 | 'show' => true, |
||
| 354 | ) ); |
||
| 355 | break; |
||
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | } |
||
| 360 | |||
| 406 |