| Conditions | 6 |
| Paths | 16 |
| Total Lines | 341 |
| Code Lines | 287 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 24 | public static function output( $post ) { |
||
| 25 | |||
| 26 | // Prepare the invoice. |
||
| 27 | $invoice = new WPInv_Invoice( $post ); |
||
| 28 | $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
||
| 29 | $customer = new WP_User( $customer ); |
||
| 30 | $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
||
| 31 | wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
||
| 32 | |||
| 33 | ?> |
||
| 34 | |||
| 35 | <style> |
||
| 36 | #wpinv-address label { |
||
| 37 | margin-bottom: 3px; |
||
| 38 | font-weight: 600; |
||
| 39 | } |
||
| 40 | </style> |
||
| 41 | <div class="bsui" style="margin-top: 1.5rem; max-width: 820px;"> |
||
| 42 | <div class="row"> |
||
| 43 | <div class="col-12 col-sm-6"> |
||
| 44 | <div id="getpaid-invoice-user-id-wrapper" class="form-group"> |
||
| 45 | <div> |
||
| 46 | <label for="post_author_override"><?php _e( 'Customer', 'invoicing' );?></label> |
||
| 47 | </div> |
||
| 48 | <div> |
||
| 49 | <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>"> |
||
| 50 | <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo sanitize_text_field( $display ); ?> </option>) |
||
| 51 | </select> |
||
| 52 | </div> |
||
| 53 | </div> |
||
| 54 | |||
| 55 | <div id="getpaid-invoice-email-wrapper" class="d-none"> |
||
| 56 | <input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" /> |
||
| 57 | <?php |
||
| 58 | echo aui()->input( |
||
| 59 | array( |
||
| 60 | 'type' => 'text', |
||
| 61 | 'id' => 'getpaid-invoice-new-user-email', |
||
| 62 | 'name' => 'wpinv_email', |
||
| 63 | 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
||
| 64 | 'label_type' => 'vertical', |
||
| 65 | 'placeholder' => '[email protected]', |
||
| 66 | 'class' => 'form-control-sm', |
||
| 67 | ) |
||
| 68 | ); |
||
| 69 | ?> |
||
| 70 | </div> |
||
| 71 | </div> |
||
| 72 | <div class="col-12 col-sm-6 form-group mt-sm-4"> |
||
| 73 | <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
||
| 74 | <a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)"> |
||
| 75 | <i aria-hidden="true" class="fa fa-refresh"></i> |
||
| 76 | <?php _e( 'Fill User Details', 'invoicing' );?> |
||
| 77 | </a> |
||
| 78 | <a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)"> |
||
| 79 | <i aria-hidden="true" class="fa fa-plus"></i> |
||
| 80 | <?php _e( 'Add New User', 'invoicing' );?> |
||
| 81 | </a> |
||
| 82 | <a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)"> |
||
| 83 | <i aria-hidden="true" class="fa fa-close"></i> |
||
| 84 | <?php _e( 'Cancel', 'invoicing' );?> |
||
| 85 | </a> |
||
| 86 | <?php endif; ?> |
||
| 87 | </div> |
||
| 88 | </div> |
||
| 89 | <div class="row"> |
||
| 90 | <div class="col-12 col-sm-6"> |
||
| 91 | <?php |
||
| 92 | echo aui()->input( |
||
| 93 | array( |
||
| 94 | 'type' => 'text', |
||
| 95 | 'id' => 'wpinv_first_name', |
||
| 96 | 'name' => 'wpinv_first_name', |
||
| 97 | 'label' => __( 'First Name', 'invoicing' ), |
||
| 98 | 'label_type' => 'vertical', |
||
| 99 | 'placeholder' => '', |
||
| 100 | 'class' => 'form-control-sm', |
||
| 101 | 'value' => $invoice->get_first_name( 'edit' ), |
||
| 102 | ) |
||
| 103 | ); |
||
| 104 | ?> |
||
| 105 | </div> |
||
| 106 | <div class="col-12 col-sm-6"> |
||
| 107 | <?php |
||
| 108 | echo aui()->input( |
||
| 109 | array( |
||
| 110 | 'type' => 'text', |
||
| 111 | 'id' => 'wpinv_last_name', |
||
| 112 | 'name' => 'wpinv_last_name', |
||
| 113 | 'label' => __( 'Last Name', 'invoicing' ), |
||
| 114 | 'label_type' => 'vertical', |
||
| 115 | 'placeholder' => '', |
||
| 116 | 'class' => 'form-control-sm', |
||
| 117 | 'value' => $invoice->get_last_name( 'edit' ), |
||
| 118 | ) |
||
| 119 | ); |
||
| 120 | ?> |
||
| 121 | </div> |
||
| 122 | </div> |
||
| 123 | |||
| 124 | <div class="row"> |
||
| 125 | <div class="col-12 col-sm-6"> |
||
| 126 | <?php |
||
| 127 | echo aui()->input( |
||
| 128 | array( |
||
| 129 | 'type' => 'text', |
||
| 130 | 'id' => 'wpinv_company', |
||
| 131 | 'name' => 'wpinv_company', |
||
| 132 | 'label' => __( 'Company', 'invoicing' ), |
||
| 133 | 'label_type' => 'vertical', |
||
| 134 | 'placeholder' => '', |
||
| 135 | 'class' => 'form-control-sm', |
||
| 136 | 'value' => $invoice->get_company( 'edit' ), |
||
| 137 | ) |
||
| 138 | ); |
||
| 139 | ?> |
||
| 140 | </div> |
||
| 141 | <div class="col-12 col-sm-6"> |
||
| 142 | <?php |
||
| 143 | echo aui()->input( |
||
| 144 | array( |
||
| 145 | 'type' => 'text', |
||
| 146 | 'id' => 'wpinv_vat_number', |
||
| 147 | 'name' => 'wpinv_vat_number', |
||
| 148 | 'label' => __( 'Vat Number', 'invoicing' ), |
||
| 149 | 'label_type' => 'vertical', |
||
| 150 | 'placeholder' => '', |
||
| 151 | 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
||
| 152 | 'value' => $invoice->get_vat_number( 'edit' ), |
||
| 153 | ) |
||
| 154 | ); |
||
| 155 | ?> |
||
| 156 | </div> |
||
| 157 | </div> |
||
| 158 | |||
| 159 | <div class="row"> |
||
| 160 | <div class="col-12 col-sm-6"> |
||
| 161 | <?php |
||
| 162 | echo aui()->input( |
||
| 163 | array( |
||
| 164 | 'type' => 'text', |
||
| 165 | 'id' => 'wpinv_address', |
||
| 166 | 'name' => 'wpinv_address', |
||
| 167 | 'label' => __( 'Address', 'invoicing' ), |
||
| 168 | 'label_type' => 'vertical', |
||
| 169 | 'placeholder' => '', |
||
| 170 | 'class' => 'form-control-sm', |
||
| 171 | 'value' => $invoice->get_address( 'edit' ), |
||
| 172 | ) |
||
| 173 | ); |
||
| 174 | ?> |
||
| 175 | </div> |
||
| 176 | <div class="col-12 col-sm-6"> |
||
| 177 | <?php |
||
| 178 | echo aui()->input( |
||
| 179 | array( |
||
| 180 | 'type' => 'text', |
||
| 181 | 'id' => 'wpinv_city', |
||
| 182 | 'name' => 'wpinv_city', |
||
| 183 | 'label' => __( 'City', 'invoicing' ), |
||
| 184 | 'label_type' => 'vertical', |
||
| 185 | 'placeholder' => '', |
||
| 186 | 'class' => 'form-control-sm', |
||
| 187 | 'value' => $invoice->get_city( 'edit' ), |
||
| 188 | ) |
||
| 189 | ); |
||
| 190 | ?> |
||
| 191 | </div> |
||
| 192 | </div> |
||
| 193 | |||
| 194 | <div class="row"> |
||
| 195 | <div class="col-12 col-sm-6"> |
||
| 196 | <?php |
||
| 197 | echo aui()->select( |
||
| 198 | array( |
||
| 199 | 'id' => 'wpinv_country', |
||
| 200 | 'name' => 'wpinv_country', |
||
| 201 | 'label' => __( 'Country', 'invoicing' ), |
||
| 202 | 'label_type' => 'vertical', |
||
| 203 | 'placeholder' => __( 'Choose a country', 'invoicing' ), |
||
| 204 | 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
||
| 205 | 'value' => $invoice->get_country( 'edit' ), |
||
| 206 | 'options' => wpinv_get_country_list(), |
||
| 207 | 'data-allow-clear' => 'false', |
||
| 208 | 'select2' => true, |
||
| 209 | ) |
||
| 210 | ); |
||
| 211 | ?> |
||
| 212 | </div> |
||
| 213 | <div class="col-12 col-sm-6"> |
||
| 214 | <?php |
||
| 215 | |||
| 216 | $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
||
| 217 | |||
| 218 | if ( empty( $states ) ) { |
||
| 219 | |||
| 220 | echo aui()->input( |
||
| 221 | array( |
||
| 222 | 'type' => 'text', |
||
| 223 | 'id' => 'wpinv_state', |
||
| 224 | 'name' => 'wpinv_state', |
||
| 225 | 'label' => __( 'State', 'invoicing' ), |
||
| 226 | 'label_type' => 'vertical', |
||
| 227 | 'placeholder' => '', |
||
| 228 | 'class' => 'form-control-sm', |
||
| 229 | 'value' => $invoice->get_state( 'edit' ), |
||
| 230 | ) |
||
| 231 | ); |
||
| 232 | |||
| 233 | } else { |
||
| 234 | |||
| 235 | echo aui()->select( |
||
| 236 | array( |
||
| 237 | 'id' => 'wpinv_state', |
||
| 238 | 'name' => 'wpinv_state', |
||
| 239 | 'label' => __( 'State', 'invoicing' ), |
||
| 240 | 'label_type' => 'vertical', |
||
| 241 | 'placeholder' => __( 'Select a state', 'invoicing' ), |
||
| 242 | 'class' => 'form-control-sm', |
||
| 243 | 'value' => $invoice->get_state( 'edit' ), |
||
| 244 | 'options' => $states, |
||
| 245 | 'data-allow-clear' => 'false', |
||
| 246 | 'select2' => true, |
||
| 247 | ) |
||
| 248 | ); |
||
| 249 | |||
| 250 | } |
||
| 251 | |||
| 252 | ?> |
||
| 253 | </div> |
||
| 254 | </div> |
||
| 255 | |||
| 256 | <div class="row"> |
||
| 257 | <div class="col-12 col-sm-6"> |
||
| 258 | <?php |
||
| 259 | echo aui()->input( |
||
| 260 | array( |
||
| 261 | 'type' => 'text', |
||
| 262 | 'id' => 'wpinv_zip', |
||
| 263 | 'name' => 'wpinv_zip', |
||
| 264 | 'label' => __( 'Zip / Postal Code', 'invoicing' ), |
||
| 265 | 'label_type' => 'vertical', |
||
| 266 | 'placeholder' => '', |
||
| 267 | 'class' => 'form-control-sm', |
||
| 268 | 'value' => $invoice->get_zip( 'edit' ), |
||
| 269 | ) |
||
| 270 | ); |
||
| 271 | ?> |
||
| 272 | </div> |
||
| 273 | <div class="col-12 col-sm-6"> |
||
| 274 | <?php |
||
| 275 | echo aui()->input( |
||
| 276 | array( |
||
| 277 | 'type' => 'text', |
||
| 278 | 'id' => 'wpinv_phone', |
||
| 279 | 'name' => 'wpinv_phone', |
||
| 280 | 'label' => __( 'Phone', 'invoicing' ), |
||
| 281 | 'label_type' => 'vertical', |
||
| 282 | 'placeholder' => '', |
||
| 283 | 'class' => 'form-control-sm', |
||
| 284 | 'value' => $invoice->get_phone( 'edit' ), |
||
| 285 | ) |
||
| 286 | ); |
||
| 287 | ?> |
||
| 288 | </div> |
||
| 289 | </div> |
||
| 290 | |||
| 291 | <?php if ( ! apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) : ?> |
||
| 292 | <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
||
| 293 | |||
| 294 | <div class="row"> |
||
| 295 | <div class="col-12 col-sm-6"> |
||
| 296 | <?php |
||
| 297 | echo aui()->select( |
||
| 298 | array( |
||
| 299 | 'id' => 'wpinv_template', |
||
| 300 | 'name' => 'wpinv_template', |
||
| 301 | 'label' => __( 'Template', 'invoicing' ), |
||
| 302 | 'label_type' => 'vertical', |
||
| 303 | 'placeholder' => __( 'Choose a template', 'invoicing' ), |
||
| 304 | 'class' => 'form-control-sm', |
||
| 305 | 'value' => $invoice->get_template( 'edit' ), |
||
| 306 | 'options' => array( |
||
| 307 | 'quantity' => __( 'Quantity', 'invoicing' ), |
||
| 308 | 'hours' => __( 'Hours', 'invoicing' ), |
||
| 309 | //'amount' => __( 'Amount Only', 'invoicing' ), |
||
| 310 | ), |
||
| 311 | 'data-allow-clear' => 'false', |
||
| 312 | 'select2' => true, |
||
| 313 | ) |
||
| 314 | ); |
||
| 315 | ?> |
||
| 316 | </div> |
||
| 317 | <div class="col-12 col-sm-6"> |
||
| 318 | <?php |
||
| 319 | |||
| 320 | // Set currency. |
||
| 321 | echo aui()->select( |
||
| 322 | array( |
||
| 323 | 'id' => 'wpinv_currency', |
||
| 324 | 'name' => 'wpinv_currency', |
||
| 325 | 'label' => __( 'Currency', 'invoicing' ), |
||
| 326 | 'label_type' => 'vertical', |
||
| 327 | 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
||
| 328 | 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
||
| 329 | 'value' => $invoice->get_currency( 'edit' ), |
||
| 330 | 'required' => false, |
||
| 331 | 'data-allow-clear' => 'false', |
||
| 332 | 'select2' => true, |
||
| 333 | 'options' => wpinv_get_currencies(), |
||
| 334 | ) |
||
| 335 | ); |
||
| 336 | |||
| 337 | ?> |
||
| 338 | </div> |
||
| 339 | </div> |
||
| 340 | |||
| 341 | <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
||
| 342 | <?php endif; ?> |
||
| 343 | |||
| 344 | <div class="row"> |
||
| 345 | <div class="col-12 col-sm-6"> |
||
| 346 | <?php |
||
| 347 | echo aui()->input( |
||
| 348 | array( |
||
| 349 | 'type' => 'text', |
||
| 350 | 'id' => 'wpinv_company_id', |
||
| 351 | 'name' => 'wpinv_company_id', |
||
| 352 | 'label' => __( 'Company ID', 'invoicing' ), |
||
| 353 | 'label_type' => 'vertical', |
||
| 354 | 'placeholder' => '', |
||
| 355 | 'class' => 'form-control-sm', |
||
| 356 | 'value' => $invoice->get_company_id( 'edit' ), |
||
| 357 | ) |
||
| 358 | ); |
||
| 359 | ?> |
||
| 360 | </div> |
||
| 361 | </div> |
||
| 362 | |||
| 363 | <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
||
| 364 | </div> |
||
| 365 | <?php |
||
| 471 |