| Conditions | 14 |
| Paths | 82 |
| Total Lines | 87 |
| Code Lines | 55 |
| 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 |
||
| 58 | public function get_data() { |
||
| 59 | global $wpdb; |
||
| 60 | |||
| 61 | $items = $this->get_stored_data( 'give_temp_reset_ids' ); |
||
| 62 | |||
| 63 | if ( ! is_array( $items ) ) { |
||
| 64 | return false; |
||
| 65 | } |
||
| 66 | |||
| 67 | $offset = ( $this->step - 1 ) * $this->per_step; |
||
| 68 | $step_items = array_slice( $items, $offset, $this->per_step ); |
||
| 69 | |||
| 70 | if ( $step_items ) { |
||
|
|
|||
| 71 | |||
| 72 | $step_ids = array( |
||
| 73 | 'customers' => array(), |
||
| 74 | 'forms' => array(), |
||
| 75 | 'other' => array(), |
||
| 76 | ); |
||
| 77 | |||
| 78 | foreach ( $step_items as $item ) { |
||
| 79 | |||
| 80 | switch ( $item['type'] ) { |
||
| 81 | case 'customer': |
||
| 82 | $step_ids['customers'][] = $item['id']; |
||
| 83 | break; |
||
| 84 | case 'forms': |
||
| 85 | $step_ids['give_forms'][] = $item['id']; |
||
| 86 | break; |
||
| 87 | default: |
||
| 88 | $item_type = apply_filters( 'give_reset_item_type', 'other', $item ); |
||
| 89 | $step_ids[ $item_type ][] = $item['id']; |
||
| 90 | break; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | $sql = array(); |
||
| 95 | $meta_table = __give_v20_bc_table_details('form' ); |
||
| 96 | |||
| 97 | foreach ( $step_ids as $type => $ids ) { |
||
| 98 | |||
| 99 | if ( empty( $ids ) ) { |
||
| 100 | continue; |
||
| 101 | } |
||
| 102 | |||
| 103 | $ids = implode( ',', $ids ); |
||
| 104 | |||
| 105 | switch ( $type ) { |
||
| 106 | case 'customers': |
||
| 107 | $sql[] = "DELETE FROM $wpdb->donors WHERE id IN ($ids)"; |
||
| 108 | $table_name = $wpdb->prefix . 'give_customers'; |
||
| 109 | $meta_table_name = $wpdb->prefix . 'give_customermeta'; |
||
| 110 | $sql[] = "DELETE FROM $table_name WHERE id IN ($ids)"; |
||
| 111 | $sql[] = "DELETE FROM $meta_table_name WHERE customer_id IN ($ids)"; |
||
| 112 | break; |
||
| 113 | case 'forms': |
||
| 114 | $sql[] = "UPDATE {$meta_table['name']} SET meta_value = 0 WHERE meta_key = '_give_form_sales' AND {$meta_table['column']['id']} IN ($ids)"; |
||
| 115 | $sql[] = "UPDATE {$meta_table['name']} SET meta_value = 0.00 WHERE meta_key = '_give_form_earnings' AND {$meta_table['column']['id']} IN ($ids)"; |
||
| 116 | break; |
||
| 117 | case 'other': |
||
| 118 | $sql[] = "DELETE FROM $wpdb->posts WHERE id IN ($ids)"; |
||
| 119 | $sql[] = "DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids)"; |
||
| 120 | $sql[] = "DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($ids)"; |
||
| 121 | $sql[] = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)"; |
||
| 122 | break; |
||
| 123 | } |
||
| 124 | |||
| 125 | if ( ! in_array( $type, array( 'customers', 'forms', 'other' ) ) ) { |
||
| 126 | // Allows other types of custom post types to filter on their own post_type |
||
| 127 | // and add items to the query list, for the IDs found in their post type. |
||
| 128 | $sql = apply_filters( "give_reset_add_queries_{$type}", $sql, $ids ); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | if ( ! empty( $sql ) ) { |
||
| 133 | foreach ( $sql as $query ) { |
||
| 134 | $wpdb->query( $query ); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | return true; |
||
| 139 | |||
| 140 | }// End if(). |
||
| 141 | |||
| 142 | return false; |
||
| 143 | |||
| 144 | } |
||
| 145 | |||
| 362 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.