Passed
Push — master ( eba4be...60f62d )
by Brian
09:36 queued 04:47
created

GetPaid_Meta_Box_Invoice_Details::output()   C

Complexity

Conditions 11
Paths 24

Size

Total Lines 158
Code Lines 112

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 112
c 1
b 0
f 0
dl 0
loc 158
rs 5.8533
cc 11
nc 24
nop 1

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
/**
4
 * Invoice Details
5
 *
6
 * Display the invoice data meta box.
7
 *
8
 */
9
10
if ( ! defined( 'ABSPATH' ) ) {
11
	exit; // Exit if accessed directly
12
}
13
14
/**
15
 * GetPaid_Meta_Box_Invoice_Details Class.
16
 */
17
class GetPaid_Meta_Box_Invoice_Details {
18
19
    /**
20
	 * Output the metabox.
21
	 *
22
	 * @param WP_Post $post
23
	 */
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" id="gdmbx2-metabox-wpinv_details">
48
49
                    <?php if ( ! $invoice->is_draft() ) : ?>
50
                        <div class="form-group">
51
                            <strong><?php _e( 'Viewed by Customer:', 'invoicing' );?></strong>
52
                            <?php ( $invoice->get_is_viewed() ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?>
53
                        </div>
54
                    <?php endif; ?>
55
56
                    <?php
57
58
                        // Date created.
59
                        echo aui()->input(
60
                            array(
61
                                'type'        => 'datepicker',
62
                                'id'          => 'wpinv_date_created',
63
                                'name'        => 'date_created',
64
                                'label'       => __( 'Invoice Date:', 'invoicing' ) . getpaid_get_help_tip( __( 'The date this invoice was created. This allows you to backdate an invoice.', 'invoicing' ) ),
65
                                'label_type'  => 'vertical',
66
                                'placeholder' => 'YYYY-MM-DD 00:00',
67
                                'class'       => 'form-control-sm',
68
                                'value'       => $invoice->get_date_created( 'edit' ),
69
                                'extra_attributes' => array(
70
                                    'data-enable-time' => 'true',
71
                                    'data-time_24hr'   => 'true',
72
                                    'data-allow-input' => 'true',
73
                                    'data-max-date'    => 'today',
74
                                ),
75
                            )
76
                        );
77
78
                        // Due date.
79
                        if ( $invoice->is_type( 'invoice' ) && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->is_draft() ) ) {
80
81
                            echo aui()->input(
82
                                array(
83
                                    'type'        => 'text',
84
                                    'id'          => 'wpinv_due_date',
85
                                    'name'        => 'wpinv_due_date',
86
                                    'label'       => __( 'Due Date:', 'invoicing' ) . getpaid_get_help_tip( __( 'Leave blank to disable automated reminder emails for this invoice.', 'invoicing' ) ),
87
                                    'label_type'  => 'vertical',
88
                                    'placeholder' => __( 'No due date', 'invoicing' ),
89
                                    'class'       => 'form-control-sm',
90
                                    'value'       => $invoice->get_due_date( 'edit' ),
91
                                )
92
                            );
93
94
                        }
95
96
                        do_action( 'wpinv_meta_box_details_after_due_date', $invoice->get_id() );
97
                        
98
                        // Status.
99
                        echo aui()->select(
100
                            array(
101
                                'id'               => 'wpinv_status',
102
                                'name'             => 'wpinv_status',
103
                                'label'            => __( 'Invoice Status:', 'invoicing' ),
104
                                'label_type'       => 'vertical',
105
                                'placeholder'      => __( 'Select Status', 'invoicing' ),
106
                                'value'            => $invoice->get_status( 'edit' ),
107
                                'select2'          => true,
108
                                'data-allow-clear' => 'false',
109
                                'options'          => wpinv_get_invoice_statuses( true )
110
                            )
111
                        );
112
113
                        // Invoice number.
114
                        echo aui()->input(
115
                            array(
116
                                'type'        => 'text',
117
                                'id'          => 'wpinv_number',
118
                                'name'        => 'wpinv_number',
119
                                'label'       => __( 'Invoice Number:', 'invoicing' ) . getpaid_get_help_tip( __( 'Each invoice number must be unique.', 'invoicing' ) ),
120
                                'label_type'  => 'vertical',
121
                                'placeholder' => __( 'Autogenerate', 'invoicing' ),
122
                                'class'       => 'form-control-sm',
123
                                'value'       => $invoice->get_number( 'edit' ),
124
                            )
125
                        );
126
127
                        // Invoice cc.
128
                        echo aui()->input(
129
                            array(
130
                                'type'        => 'text',
131
                                'id'          => 'wpinv_cc',
132
                                'name'        => 'wpinv_cc',
133
                                'label'       => __( 'Email CC:', 'invoicing' ) . getpaid_get_help_tip( __( 'Enter a comma separated list of other emails that should be notified about the invoice.', 'invoicing' ) ),
134
                                'label_type'  => 'vertical',
135
                                'placeholder' => __( '[email protected], [email protected]', 'invoicing' ),
136
                                'class'       => 'form-control-sm',
137
                                'value'       => $invoice->get_email_cc( 'edit' ),
138
                            )
139
                        );
140
141
                        do_action( 'wpinv_meta_box_details_inner', $invoice->get_id() );
142
143
                        // Disable taxes.
144
                        if ( wpinv_use_taxes() && ! ( $invoice->is_paid() || $invoice->is_refunded() ) ) {
145
146
                            echo aui()->input(
147
                                array(
148
                                    'id'          => 'wpinv_taxable',
149
                                    'name'        => 'disable_taxes',
150
                                    'type'        => 'checkbox',
151
                                    'label'       => __( 'Disable taxes', 'invoicing' ),
152
                                    'value'       => '1',
153
                                    'checked'     => (bool) $invoice->get_disable_taxes(),
154
                                )
155
                            );
156
157
                        }
158
159
                        // Apply a discount.
160
                        if ( $invoice->get_discount_code( 'edit' ) ) {
161
162
                            echo aui()->input(
163
                                array(
164
                                    'type'        => 'text',
165
                                    'id'          => 'wpinv_discount_code',
166
                                    'name'        => 'wpinv_discount_code',
167
                                    'label'       => __( 'Discount Code:', 'invoicing' ),
168
                                    'label_type'  => 'vertical',
169
                                    'class'       => 'form-control-sm',
170
                                    'value'       => $invoice->get_discount_code( 'edit' ),
171
                                    'extra_attributes' => array(
172
                                        'onclick'  => 'this.select();',
173
                                        'readonly' => 'true',
174
                                    ),
175
                                )
176
                            );
177
178
                        }
179
180
                    ?>
181
182
                </div>
183
184
        <?php
185
    }
186
}
187