| Conditions | 23 |
| Paths | 545 |
| Total Lines | 107 |
| Code Lines | 70 |
| 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 |
||
| 80 | global $wpinv_options; |
||
| 81 | |||
| 82 | $current_options = get_option( 'wpinv_settings', array() ); |
||
| 83 | $options = array( |
||
| 84 | 'email_new_invoice_body' => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ), |
||
| 85 | 'email_cancelled_invoice_body' => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ), |
||
| 86 | 'email_failed_invoice_body' => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ), |
||
| 87 | 'email_onhold_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ), |
||
| 88 | 'email_processing_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ), |
||
| 89 | 'email_refunded_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ), |
||
| 90 | 'email_user_invoice_body' => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
||
| 91 | 'email_user_note_body' => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ), |
||
| 92 | 'email_overdue_body' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
||
| 93 | ); |
||
| 94 | |||
| 95 | foreach ($options as $option => $value){ |
||
| 96 | if (!isset($current_options[$option])) { |
||
| 97 | $current_options[$option] = $value; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | $wpinv_options = $current_options; |
||
| 102 | |||
| 103 | update_option( 'wpinv_settings', $current_options ); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Version 119 upgrades. |
||
| 108 | */ |
||
| 109 | function wpinv_v119_upgrades() { |
||
| 110 | wpinv_create_invoices_table(); |
||
| 111 | wpinv_convert_old_invoices(); |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Creates the invoices table. |
||
| 116 | */ |
||
| 117 | function wpinv_create_invoices_table() { |
||
| 118 | global $wpdb; |
||
| 119 | |||
| 120 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
||
| 121 | |||
| 122 | // Create invoices table. |
||
| 123 | $table = $wpdb->prefix . 'getpaid_invoices'; |
||
| 124 | $sql = "CREATE TABLE $table ( |
||
| 125 | |||
| 126 | post_id BIGINT(20) NOT NULL, |
||
| 127 | `number` VARCHAR(100), |
||
| 128 | `key` VARCHAR(100), |
||
| 129 | `type` VARCHAR(100) NOT NULL DEFAULT 'invoice', |
||
| 130 | mode VARCHAR(100) NOT NULL DEFAULT 'live', |
||
| 131 | |||
| 132 | user_ip VARCHAR(100), |
||
| 133 | first_name VARCHAR(100), |
||
| 134 | last_name VARCHAR(100), |
||
| 135 | `address` VARCHAR(100), |
||
| 136 | city VARCHAR(100), |
||
| 137 | `state` VARCHAR(100), |
||
| 138 | country VARCHAR(100), |
||
| 139 | zip VARCHAR(100), |
||
| 140 | adddress_confirmed INT(10), |
||
| 141 | |||
| 142 | gateway VARCHAR(100), |
||
| 143 | transaction_id VARCHAR(100), |
||
| 144 | currency VARCHAR(10), |
||
| 145 | subtotal FLOAT NOT NULL DEFAULT 0, |
||
| 146 | tax FLOAT NOT NULL DEFAULT 0, |
||
| 147 | fees_total FLOAT NOT NULL DEFAULT 0, |
||
| 148 | total FLOAT NOT NULL DEFAULT 0, |
||
| 149 | discount FLOAT NOT NULL DEFAULT 0, |
||
| 150 | discount_code VARCHAR(100), |
||
| 151 | disable_taxes INT(2) NOT NULL DEFAULT 0, |
||
| 152 | due_date DATETIME, |
||
| 153 | completed_date DATETIME, |
||
| 154 | company VARCHAR(100), |
||
| 155 | vat_number VARCHAR(100), |
||
| 156 | vat_rate VARCHAR(100), |
||
| 157 | |||
| 158 | custom_meta TEXT, |
||
| 159 | PRIMARY KEY (post_id), |
||
| 160 | KEY number (number), |
||
| 161 | KEY `key` ( `key` ) |
||
| 162 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
||
| 163 | |||
| 164 | dbDelta( $sql ); |
||
| 165 | |||
| 166 | // Create invoice items table. |
||
| 167 | $table = $wpdb->prefix . 'getpaid_invoice_items'; |
||
| 168 | $sql = "CREATE TABLE $table ( |
||
| 169 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
||
| 170 | post_id BIGINT(20) NOT NULL, |
||
| 171 | |||
| 172 | item_id BIGINT(20) NOT NULL, |
||
| 173 | item_name TEXT NOT NULL, |
||
| 174 | item_description TEXT NOT NULL, |
||
| 175 | |||
| 176 | vat_rate FLOAT NOT NULL DEFAULT 0, |
||
| 177 | vat_class VARCHAR(100), |
||
| 178 | tax FLOAT NOT NULL DEFAULT 0, |
||
| 179 | item_price FLOAT NOT NULL DEFAULT 0, |
||
| 180 | custom_price FLOAT NOT NULL DEFAULT 0, |
||
| 181 | quantity INT(20) NOT NULL DEFAULT 1, |
||
| 182 | discount FLOAT NOT NULL DEFAULT 0, |
||
| 183 | subtotal FLOAT NOT NULL DEFAULT 0, |
||
| 184 | price FLOAT NOT NULL DEFAULT 0, |
||
| 185 | meta TEXT, |
||
| 186 | fees TEXT, |
||
| 187 | PRIMARY KEY (ID), |
||
| 310 |