| Conditions | 5 |
| Paths | 3 |
| Total Lines | 54 |
| 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 |
||
| 60 | public static function donated( $args = array() ) { |
||
| 61 | global $wpdb; |
||
| 62 | $donation_id_col = Give()->payment_meta->get_meta_type() . '_id'; |
||
| 63 | |||
| 64 | $donated_amount = ''; |
||
| 65 | |||
| 66 | if ( empty( $args['donor'] ) ) { |
||
| 67 | return $donated_amount; |
||
| 68 | } |
||
| 69 | |||
| 70 | $args['output'] = 'posts'; |
||
| 71 | $args['status'] = 'publish'; |
||
| 72 | $args['fields'] = 'ids'; |
||
| 73 | $args['number'] = - 1; |
||
| 74 | |||
| 75 | $donation_query = new Give_Payments_Query( $args ); |
||
| 76 | $donations = $donation_query->get_payments(); |
||
| 77 | $donation_id_str = implode( '\',\'', $donations ); |
||
| 78 | |||
| 79 | $query = "SELECT {$donation_id_col} as id, meta_value as total |
||
| 80 | FROM {$wpdb->donationmeta} |
||
| 81 | WHERE meta_key='_give_payment_total' |
||
| 82 | AND {$donation_id_col} IN ('{$donation_id_str}')"; |
||
| 83 | |||
| 84 | $donated_amounts = $wpdb->get_results( $query, ARRAY_A ); |
||
| 85 | |||
| 86 | if ( ! empty( $donated_amounts ) ) { |
||
| 87 | foreach ( $donated_amounts as $donation ) { |
||
| 88 | $currency_code = give_get_payment_currency_code( $donation['id'] ); |
||
| 89 | /** |
||
| 90 | * Filter the donation amount |
||
| 91 | * Note: this filter documented in payments/functions.php:give_donation_amount() |
||
| 92 | * |
||
| 93 | * @since 2.1 |
||
| 94 | */ |
||
| 95 | $formatted_amount = apply_filters( |
||
| 96 | 'give_donation_amount', |
||
| 97 | give_format_amount( $donation['total'], array( 'currency' => $currency_code ) ), |
||
| 98 | $donation['total'], |
||
| 99 | $donation['id'], |
||
| 100 | array( 'type' => 'stats', 'currency' => false, 'amount' => false ) |
||
| 101 | ); |
||
| 102 | |||
| 103 | if( ! is_numeric( $formatted_amount ) ) { |
||
| 104 | error_log( print_r( $formatted_amount, true ) . "\n", 3, WP_CONTENT_DIR . '/debug_new.log' ); |
||
| 105 | } |
||
| 106 | |||
| 107 | $donated_amount = (float) give_maybe_sanitize_amount( $formatted_amount, array( 'currency' => $currency_code ) ); |
||
| 108 | $donated_amount += $donated_amount; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | return $donated_amount; |
||
| 113 | } |
||
| 114 | } |
||
| 115 |