| Conditions | 16 |
| Paths | 48 |
| Total Lines | 210 |
| Code Lines | 145 |
| 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 | |||
| 29 | // Nonce field. |
||
| 30 | wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ; |
||
| 31 | |||
| 32 | |||
| 33 | ?> |
||
| 34 | |||
| 35 | <style> |
||
| 36 | #poststuff .input-group-text, |
||
| 37 | #poststuff .form-control { |
||
| 38 | border-color: #7e8993; |
||
| 39 | } |
||
| 40 | |||
| 41 | #wpinv-details label { |
||
| 42 | margin-bottom: 3px; |
||
| 43 | font-weight: 600; |
||
| 44 | } |
||
| 45 | </style> |
||
| 46 | |||
| 47 | <div class="bsui" style="margin-top: 1.5rem"> |
||
| 48 | |||
| 49 | <?php do_action( 'getpaid_invoice_edit_before_viewed_by_customer', $invoice ); ?> |
||
| 50 | <?php if ( ! $invoice->is_draft() ) : ?> |
||
| 51 | <div class="form-group"> |
||
| 52 | <strong><?php _e( 'Viewed by Customer:', 'invoicing' );?></strong> |
||
| 53 | <?php ( $invoice->get_is_viewed() ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?> |
||
| 54 | </div> |
||
| 55 | <?php endif; ?> |
||
| 56 | |||
| 57 | <?php |
||
| 58 | |||
| 59 | // Date created. |
||
| 60 | $label = sprintf( |
||
| 61 | __( '%s Date:', 'invoicing' ), |
||
| 62 | ucfirst( $invoice->get_invoice_quote_type() ) |
||
| 63 | ); |
||
| 64 | |||
| 65 | $info = sprintf( |
||
| 66 | __( 'The date this %s was created.', 'invoicing' ), |
||
| 67 | strtolower( $invoice->get_invoice_quote_type() ) |
||
| 68 | ); |
||
| 69 | |||
| 70 | echo aui()->input( |
||
| 71 | array( |
||
| 72 | 'type' => 'datepicker', |
||
| 73 | 'id' => 'wpinv_date_created', |
||
| 74 | 'name' => 'date_created', |
||
| 75 | 'label' => $label . getpaid_get_help_tip( $info ), |
||
| 76 | 'label_type' => 'vertical', |
||
| 77 | 'placeholder' => 'YYYY-MM-DD 00:00', |
||
| 78 | 'class' => 'form-control-sm', |
||
| 79 | 'value' => $invoice->get_date_created( 'edit' ), |
||
| 80 | 'extra_attributes' => array( |
||
| 81 | 'data-enable-time' => 'true', |
||
| 82 | 'data-time_24hr' => 'true', |
||
| 83 | 'data-allow-input' => 'true', |
||
| 84 | 'data-max-date' => 'today', |
||
| 85 | ), |
||
| 86 | ) |
||
| 87 | ); |
||
| 88 | |||
| 89 | // Date paid. |
||
| 90 | $date_paid = $invoice->get_date_completed( 'edit' ); |
||
| 91 | if ( ! empty( $date_paid ) && $invoice->is_paid() ) { |
||
| 92 | |||
| 93 | echo aui()->input( |
||
| 94 | array( |
||
| 95 | 'type' => 'text', |
||
| 96 | 'id' => 'wpinv_date_completed', |
||
| 97 | 'name' => 'wpinv_date_completed', |
||
| 98 | 'label' => __( 'Date Completed:', 'invoicing' ), |
||
| 99 | 'label_type' => 'vertical', |
||
| 100 | 'class' => 'form-control-sm', |
||
| 101 | 'value' => $date_paid, |
||
| 102 | 'extra_attributes' => array( |
||
| 103 | 'onclick' => 'this.select();', |
||
| 104 | 'readonly' => 'true', |
||
| 105 | ), |
||
| 106 | ) |
||
| 107 | ); |
||
| 108 | |||
| 109 | } |
||
| 110 | |||
| 111 | // Due date. |
||
| 112 | if ( $invoice->is_type( 'invoice' ) && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->is_draft() ) ) { |
||
| 113 | |||
| 114 | echo aui()->input( |
||
| 115 | array( |
||
| 116 | 'type' => 'text', |
||
| 117 | 'id' => 'wpinv_due_date', |
||
| 118 | 'name' => 'wpinv_due_date', |
||
| 119 | 'label' => __( 'Due Date:', 'invoicing' ) . getpaid_get_help_tip( __( 'Leave blank to disable automated reminder emails for this invoice.', 'invoicing' ) ), |
||
| 120 | 'label_type' => 'vertical', |
||
| 121 | 'placeholder' => __( 'No due date', 'invoicing' ), |
||
| 122 | 'class' => 'form-control-sm', |
||
| 123 | 'value' => $invoice->get_due_date( 'edit' ), |
||
| 124 | ) |
||
| 125 | ); |
||
| 126 | |||
| 127 | } |
||
| 128 | |||
| 129 | do_action( 'wpinv_meta_box_details_after_due_date', $invoice->get_id() ); |
||
| 130 | do_action( 'getpaid_metabox_after_due_date', $invoice ); |
||
| 131 | |||
| 132 | // Status. |
||
| 133 | $label = sprintf( |
||
| 134 | __( '%s Status:', 'invoicing' ), |
||
| 135 | ucfirst( $invoice->get_invoice_quote_type() ) |
||
| 136 | ); |
||
| 137 | |||
| 138 | $status = $invoice->get_status( 'edit' ); |
||
| 139 | echo aui()->select( |
||
| 140 | array( |
||
| 141 | 'id' => 'wpinv_status', |
||
| 142 | 'name' => 'wpinv_status', |
||
| 143 | 'label' => $label, |
||
| 144 | 'label_type' => 'vertical', |
||
| 145 | 'placeholder' => __( 'Select Status', 'invoicing' ), |
||
| 146 | 'value' => array_key_exists( $status, $invoice->get_all_statuses() ) ? $status : $invoice->get_default_status(), |
||
| 147 | 'select2' => true, |
||
| 148 | 'data-allow-clear' => 'false', |
||
| 149 | 'options' => wpinv_get_invoice_statuses( true, false, $invoice ) |
||
| 150 | ) |
||
| 151 | ); |
||
| 152 | |||
| 153 | // Invoice number. |
||
| 154 | $label = sprintf( |
||
| 155 | __( '%s Number:', 'invoicing' ), |
||
| 156 | ucfirst( $invoice->get_invoice_quote_type() ) |
||
| 157 | ); |
||
| 158 | |||
| 159 | $info = sprintf( |
||
| 160 | __( 'Each %s number must be unique.', 'invoicing' ), |
||
| 161 | strtolower( $invoice->get_invoice_quote_type() ) |
||
| 162 | ); |
||
| 163 | |||
| 164 | echo aui()->input( |
||
| 165 | array( |
||
| 166 | 'type' => 'text', |
||
| 167 | 'id' => 'wpinv_number', |
||
| 168 | 'name' => 'wpinv_number', |
||
| 169 | 'label' => $label . getpaid_get_help_tip( $info ), |
||
| 170 | 'label_type' => 'vertical', |
||
| 171 | 'placeholder' => __( 'Autogenerate', 'invoicing' ), |
||
| 172 | 'class' => 'form-control-sm', |
||
| 173 | 'value' => $invoice->get_number( 'edit' ), |
||
| 174 | ) |
||
| 175 | ); |
||
| 176 | |||
| 177 | // Invoice cc. |
||
| 178 | echo aui()->input( |
||
| 179 | array( |
||
| 180 | 'type' => 'text', |
||
| 181 | 'id' => 'wpinv_cc', |
||
| 182 | 'name' => 'wpinv_cc', |
||
| 183 | 'label' => __( 'Email CC:', 'invoicing' ) . getpaid_get_help_tip( __( 'Enter a comma separated list of other emails that should be notified about the invoice.', 'invoicing' ) ), |
||
| 184 | 'label_type' => 'vertical', |
||
| 185 | 'placeholder' => __( '[email protected], [email protected]', 'invoicing' ), |
||
| 186 | 'class' => 'form-control-sm', |
||
| 187 | 'value' => $invoice->get_email_cc( 'edit' ), |
||
| 188 | ) |
||
| 189 | ); |
||
| 190 | |||
| 191 | do_action( 'wpinv_meta_box_details_inner', $invoice->get_id() ); |
||
| 192 | |||
| 193 | // Disable taxes. |
||
| 194 | if ( wpinv_use_taxes() && ! ( $invoice->is_paid() || $invoice->is_refunded() ) ) { |
||
| 195 | |||
| 196 | echo aui()->input( |
||
| 197 | array( |
||
| 198 | 'id' => 'wpinv_taxable', |
||
| 199 | 'name' => 'disable_taxes', |
||
| 200 | 'type' => 'checkbox', |
||
| 201 | 'label' => __( 'Disable taxes', 'invoicing' ), |
||
| 202 | 'value' => '1', |
||
| 203 | 'checked' => (bool) $invoice->get_disable_taxes(), |
||
| 204 | ) |
||
| 205 | ); |
||
| 206 | |||
| 207 | } |
||
| 208 | |||
| 209 | // Apply a discount. |
||
| 210 | if ( ( $invoice->is_paid() || $invoice->is_refunded() ) && $invoice->get_discount_code( 'edit' ) ) { |
||
| 211 | |||
| 212 | echo aui()->input( |
||
| 213 | array( |
||
| 214 | 'type' => 'text', |
||
| 215 | 'id' => 'wpinv_discount_code', |
||
| 216 | 'name' => 'wpinv_discount_code', |
||
| 217 | 'label' => __( 'Discount Code:', 'invoicing' ), |
||
| 218 | 'label_type' => 'vertical', |
||
| 219 | 'class' => 'form-control-sm', |
||
| 220 | 'value' => $invoice->get_discount_code( 'edit' ), |
||
| 221 | 'extra_attributes' => array( |
||
| 222 | 'onclick' => 'this.select();', |
||
| 223 | 'readonly' => 'true', |
||
| 224 | ), |
||
| 225 | ) |
||
| 226 | ); |
||
| 227 | |||
| 228 | } |
||
| 229 | |||
| 230 | do_action( 'getpaid_metabox_after_invoice_details', $invoice ); |
||
| 231 | |||
| 232 | ?> |
||
| 233 | |||
| 234 | </div> |
||
| 239 |