| Conditions | 20 | 
| Paths | > 20000 | 
| Total Lines | 205 | 
| Code Lines | 159 | 
| 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  | 
            ||
| 8 |     public static function output( $post ) { | 
            ||
| 9 | global $wpinv_euvat, $ajax_cart_details;  | 
            ||
| 10 | |||
| 11 | $post_id = !empty( $post->ID ) ? $post->ID : 0;  | 
            ||
| 12 | $invoice = new WPInv_Invoice( $post_id );  | 
            ||
| 13 | $ajax_cart_details = $invoice->get_cart_details();  | 
            ||
| 14 | $subtotal = $invoice->get_subtotal( true );  | 
            ||
| 15 | $discount_raw = $invoice->get_discount();  | 
            ||
| 16 | $discount = wpinv_price( $discount_raw, $invoice->get_currency() );  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 17 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : '';  | 
            ||
| 18 | $tax = $invoice->get_tax( true );  | 
            ||
| 19 | $total = $invoice->get_total( true );  | 
            ||
| 20 | $item_quantities = wpinv_item_quantities_enabled();  | 
            ||
| 21 | $use_taxes = wpinv_use_taxes();  | 
            ||
| 22 |         if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) { | 
            ||
| 23 | $use_taxes = true;  | 
            ||
| 24 | }  | 
            ||
| 25 | $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );  | 
            ||
| 26 | $is_recurring = $invoice->is_recurring();  | 
            ||
| 27 | $post_type_object = get_post_type_object($invoice->post_type);  | 
            ||
| 28 | $type_title = $post_type_object->labels->singular_name;  | 
            ||
| 29 | |||
| 30 | $cols = 5;  | 
            ||
| 31 |         if ( $item_quantities ) { | 
            ||
| 32 | $cols++;  | 
            ||
| 33 | }  | 
            ||
| 34 |         if ( $use_taxes ) { | 
            ||
| 35 | $cols++;  | 
            ||
| 36 | }  | 
            ||
| 37 | $class = '';  | 
            ||
| 38 |         if ( $invoice->is_paid() ) { | 
            ||
| 39 | $class .= ' wpinv-paid';  | 
            ||
| 40 | }  | 
            ||
| 41 |         if ( $invoice->is_refunded() ) { | 
            ||
| 42 | $class .= ' wpinv-refunded';  | 
            ||
| 43 | }  | 
            ||
| 44 |         if ( $is_recurring ) { | 
            ||
| 45 | $class .= ' wpi-recurring';  | 
            ||
| 46 | }  | 
            ||
| 47 | ?>  | 
            ||
| 48 | <div class="wpinv-items-wrap<?php echo $class; ?>" id="wpinv_items_wrap" data-status="<?php echo $invoice->status; ?>">  | 
            ||
| 49 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">  | 
            ||
| 50 | <thead>  | 
            ||
| 51 | <tr>  | 
            ||
| 52 | <th class="id"><?php _e( 'ID', 'invoicing' );?></th>  | 
            ||
| 53 | <th class="title"><?php _e( 'Item', 'invoicing' );?></th>  | 
            ||
| 54 | <th class="price"><?php _e( 'Price', 'invoicing' );?></th>  | 
            ||
| 55 |                         <?php if ( $item_quantities ) { ?> | 
            ||
| 56 | <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>  | 
            ||
| 57 | <?php } ?>  | 
            ||
| 58 | <th class="total"><?php _e( 'Total', 'invoicing' );?></th>  | 
            ||
| 59 |                         <?php if ( $use_taxes ) { ?> | 
            ||
| 60 | <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>  | 
            ||
| 61 | <?php } ?>  | 
            ||
| 62 | <th class="action"></th>  | 
            ||
| 63 | </tr>  | 
            ||
| 64 | </thead>  | 
            ||
| 65 | <tbody class="wpinv-line-items">  | 
            ||
| 66 | <?php echo wpinv_admin_get_line_items( $invoice ); ?>  | 
            ||
| 67 | </tbody>  | 
            ||
| 68 | <tfoot class="wpinv-totals">  | 
            ||
| 69 | <tr>  | 
            ||
| 70 | <td colspan="<?php echo $cols; ?>" style="padding:0;border:0">  | 
            ||
| 71 | <div id="wpinv-quick-add">  | 
            ||
| 72 | <table cellspacing="0" cellpadding="0">  | 
            ||
| 73 | <tr>  | 
            ||
| 74 | <td class="id">  | 
            ||
| 75 | </td>  | 
            ||
| 76 | <td class="title">  | 
            ||
| 77 | <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]">  | 
            ||
| 78 |                                             <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> | 
            ||
| 79 | <div class="wp-clearfix">  | 
            ||
| 80 | <label class="wpi-vat-rule">  | 
            ||
| 81 | <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>  | 
            ||
| 82 | <span class="input-text-wrap">  | 
            ||
| 83 | <?php echo wpinv_html_select( array(  | 
            ||
| 84 | 'options' => $wpinv_euvat->get_rules(),  | 
            ||
| 85 | 'name' => '_wpinv_quick[vat_rule]',  | 
            ||
| 86 | 'id' => '_wpinv_quick_vat_rule',  | 
            ||
| 87 | 'show_option_all' => false,  | 
            ||
| 88 | 'show_option_none' => false,  | 
            ||
| 89 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule wpi_select2',  | 
            ||
| 90 | ) ); ?>  | 
            ||
| 91 | </span>  | 
            ||
| 92 | </label>  | 
            ||
| 93 | </div>  | 
            ||
| 94 |                                             <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> | 
            ||
| 95 | <div class="wp-clearfix">  | 
            ||
| 96 | <label class="wpi-vat-class">  | 
            ||
| 97 | <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>  | 
            ||
| 98 | <span class="input-text-wrap">  | 
            ||
| 99 | <?php echo wpinv_html_select( array(  | 
            ||
| 100 | 'options' => $wpinv_euvat->get_all_classes(),  | 
            ||
| 101 | 'name' => '_wpinv_quick[vat_class]',  | 
            ||
| 102 | 'id' => '_wpinv_quick_vat_class',  | 
            ||
| 103 | 'show_option_all' => false,  | 
            ||
| 104 | 'show_option_none' => false,  | 
            ||
| 105 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class wpi_select2',  | 
            ||
| 106 | ) ); ?>  | 
            ||
| 107 | </span>  | 
            ||
| 108 | </label>  | 
            ||
| 109 | </div>  | 
            ||
| 110 | <?php } ?>  | 
            ||
| 111 | <div class="wp-clearfix">  | 
            ||
| 112 | <label class="wpi-item-type">  | 
            ||
| 113 | <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>  | 
            ||
| 114 | <span class="input-text-wrap">  | 
            ||
| 115 | <?php echo wpinv_html_select( array(  | 
            ||
| 116 | 'options' => $item_types,  | 
            ||
| 117 | 'name' => '_wpinv_quick[type]',  | 
            ||
| 118 | 'id' => '_wpinv_quick_type',  | 
            ||
| 119 | 'selected' => 'custom',  | 
            ||
| 120 | 'show_option_all' => false,  | 
            ||
| 121 | 'show_option_none' => false,  | 
            ||
| 122 | 'class' => 'gdmbx2-text-medium wpinv-quick-type wpi_select2',  | 
            ||
| 123 | ) ); ?>  | 
            ||
| 124 | </span>  | 
            ||
| 125 | </label>  | 
            ||
| 126 | </div>  | 
            ||
| 127 | |||
| 128 | <div class="wp-clearfix">  | 
            ||
| 129 | <?php  | 
            ||
| 130 | echo wpinv_html_textarea( array(  | 
            ||
| 131 | 'name' => '_wpinv_quick[excerpt]',  | 
            ||
| 132 | 'id' => '_wpinv_quick_excerpt',  | 
            ||
| 133 | 'value' => '',  | 
            ||
| 134 | 'class' => 'large-text',  | 
            ||
| 135 | 'label' => __( 'Item description', 'invoicing' ),  | 
            ||
| 136 | ) );  | 
            ||
| 137 | ?>  | 
            ||
| 138 | </div>  | 
            ||
| 139 | |||
| 140 | <div class="wp-clearfix">  | 
            ||
| 141 | <label class="wpi-item-actions">  | 
            ||
| 142 | <span class="input-text-wrap">  | 
            ||
| 143 | <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item">  | 
            ||
| 144 | </span>  | 
            ||
| 145 | </label>  | 
            ||
| 146 | </div>  | 
            ||
| 147 | </td>  | 
            ||
| 148 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>  | 
            ||
| 149 |                                         <?php if ( $item_quantities ) { ?> | 
            ||
| 150 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>  | 
            ||
| 151 | <?php } ?>  | 
            ||
| 152 | <td class="total"></td>  | 
            ||
| 153 |                                         <?php if ( $use_taxes ) { ?> | 
            ||
| 154 | <td class="tax"></td>  | 
            ||
| 155 | <?php } ?>  | 
            ||
| 156 | <td class="action"></td>  | 
            ||
| 157 | </tr>  | 
            ||
| 158 | </table>  | 
            ||
| 159 | </div>  | 
            ||
| 160 | </td>  | 
            ||
| 161 | </tr>  | 
            ||
| 162 | <tr class="clear">  | 
            ||
| 163 | <td colspan="<?php echo $cols; ?>"></td>  | 
            ||
| 164 | </tr>  | 
            ||
| 165 | <tr class="totals">  | 
            ||
| 166 | <td colspan="<?php echo ( $cols - 4 ); ?>"></td>  | 
            ||
| 167 | <td colspan="4">  | 
            ||
| 168 | <table cellspacing="0" cellpadding="0">  | 
            ||
| 169 | <tr class="subtotal">  | 
            ||
| 170 | <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>  | 
            ||
| 171 | <td class="total"><?php echo $subtotal;?></td>  | 
            ||
| 172 | <td class="action"></td>  | 
            ||
| 173 | </tr>  | 
            ||
| 174 | <tr class="discount">  | 
            ||
| 175 | <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>  | 
            ||
| 176 | <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>  | 
            ||
| 177 | <td class="action"></td>  | 
            ||
| 178 | </tr>  | 
            ||
| 179 |                                 <?php if ( $use_taxes ) { ?> | 
            ||
| 180 | <tr class="tax">  | 
            ||
| 181 | <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>  | 
            ||
| 182 | <td class="total"><?php echo $tax;?></td>  | 
            ||
| 183 | <td class="action"></td>  | 
            ||
| 184 | </tr>  | 
            ||
| 185 | <?php } ?>  | 
            ||
| 186 | <tr class="total">  | 
            ||
| 187 | <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>  | 
            ||
| 188 | <td class="total"><?php echo $total;?></td>  | 
            ||
| 189 | <td class="action"></td>  | 
            ||
| 190 | </tr>  | 
            ||
| 191 | </table>  | 
            ||
| 192 | </td>  | 
            ||
| 193 | </tr>  | 
            ||
| 194 | </tfoot>  | 
            ||
| 195 | </table>  | 
            ||
| 196 | <div class="wpinv-actions">  | 
            ||
| 197 | <?php ob_start(); ?>  | 
            ||
| 198 | <?php  | 
            ||
| 199 |                     if ( !$invoice->is_paid() && !$invoice->is_refunded() ) { | 
            ||
| 200 |                         if ( !$invoice->is_recurring() ) { | 
            ||
| 201 | echo wpinv_item_dropdown( array(  | 
            ||
| 202 | 'name' => 'wpinv_invoice_item',  | 
            ||
| 203 | 'id' => 'wpinv_invoice_item',  | 
            ||
| 204 | 'show_recurring' => true,  | 
            ||
| 205 | 'class' => 'wpi_select2',  | 
            ||
| 206 | ) );  | 
            ||
| 207 | ?>  | 
            ||
| 208 | <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">  | 
            ||
| 209 | <?php } ?>  | 
            ||
| 210 | <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>  | 
            ||
| 211 | <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?>  | 
            ||
| 212 | </div>  | 
            ||
| 213 | </div>  | 
            ||
| 514 |