Passed
Pull Request — master (#377)
by Brian
06:57
created

GetPaid_Meta_Box_Invoice_Address::output()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 272
Code Lines 237

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 237
c 1
b 0
f 0
dl 0
loc 272
rs 7.6888
cc 5
nc 4
nop 1

How to fix   Long Method   

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 Address
5
 *
6
 * Display the invoice address meta box.
7
 *
8
 */
9
10
if ( ! defined( 'ABSPATH' ) ) {
11
	exit; // Exit if accessed directly
12
}
13
14
/**
15
 * GetPaid_Meta_Box_Invoice_Address Class.
16
 */
17
class GetPaid_Meta_Box_Invoice_Address {
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
        wp_nonce_field( 'wpinv_save_invoice', 'wpinv_save_invoice' )
30
31
        ?>
32
33
        <style>
34
            #gdmbx2-metabox-wpinv_address label {
35
                margin-bottom: 3px;
36
                font-weight: 600;
37
            }
38
        </style>
39
            <div class="bsui" style="margin-top: 1.5rem; max-width: 820px;">
40
                <div id="gdmbx2-metabox-wpinv_address">
41
                    <div class="row">
42
                        <div class="col-12 col-sm-6">
43
                            <div id="getpaid-invoice-user-id-wrapper" class="form-group">
44
                                <div>
45
                                    <label for="post_author_override"><?php _e( 'Customer', 'invoicing' );?></label>
46
                                </div>
47
                                <?php 
48
                                    wpinv_dropdown_users(
49
                                        array(
50
                                            'name'             => 'post_author_override',
51
                                            'selected'         => $invoice->get_id() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(),
52
                                            'include_selected' => true,
53
                                            'show'             => 'display_name_with_email',
54
                                            'orderby'          => 'user_email',
55
                                            'class'            => 'wpi_select2 form-control'
56
                                        )
57
                                    );
58
                                ?>
59
                            </div>
60
61
                            <div id="getpaid-invoice-email-wrapper" class="d-none">
62
                                <input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" />
63
                                <?php
64
                                    echo aui()->input(
65
                                        array(
66
                                            'type'        => 'email',
67
                                            'id'          => 'getpaid-invoice-new-user-email',
68
                                            'name'        => 'wpinv_email',
69
                                            'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
70
                                            'label_type'  => 'vertical',
71
                                            'placeholder' => '[email protected]',
72
                                            'class'       => 'form-control-sm',
73
                                            'value'       => $invoice->get_state( 'edit' ),
74
                                        )
75
                                    );
76
                                ?>
77
                            </div>
78
                        </div>
79
                        <div class="col-12 col-sm-6 form-group mt-sm-4">
80
                            <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?>
81
                                <a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)">
82
                                    <i aria-hidden="true" class="fa fa-refresh"></i>
83
                                    <?php _e( 'Fill User Details', 'invoicing' );?>
84
                                </a>
85
                                <a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)">
86
                                    <i aria-hidden="true" class="fa fa-plus"></i>
87
                                    <?php _e( 'Add New User', 'invoicing' );?>
88
                                </a>
89
                                <a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)">
90
                                    <i aria-hidden="true" class="fa fa-close"></i>
91
                                    <?php _e( 'Cancel', 'invoicing' );?>
92
                                </a>
93
                            <?php endif; ?>
94
                        </div>
95
                    </div>
96
                    <div class="row">
97
                        <div class="col-12 col-sm-6">
98
                            <?php
99
                                echo aui()->input(
100
                                    array(
101
                                        'type'        => 'text',
102
                                        'id'          => 'wpinv_first_name',
103
                                        'name'        => 'wpinv_first_name',
104
                                        'label'       => __( 'First Name', 'invoicing' ),
105
                                        'label_type'  => 'vertical',
106
                                        'placeholder' => 'Jane',
107
                                        'class'       => 'form-control-sm',
108
                                        'value'       => $invoice->get_first_name( 'edit' ),
109
                                    )
110
                                );
111
                            ?>
112
                        </div>
113
                        <div class="col-12 col-sm-6">
114
                            <?php
115
                                echo aui()->input(
116
                                    array(
117
                                        'type'        => 'text',
118
                                        'id'          => 'wpinv_last_name',
119
                                        'name'        => 'wpinv_last_name',
120
                                        'label'       => __( 'Last Name', 'invoicing' ),
121
                                        'label_type'  => 'vertical',
122
                                        'placeholder' => 'Doe',
123
                                        'class'       => 'form-control-sm',
124
                                        'value'       => $invoice->get_last_name( 'edit' ),
125
                                    )
126
                                );
127
                            ?>
128
                        </div>
129
                    </div>
130
131
                    <div class="row">
132
                        <div class="col-12 col-sm-6">
133
                            <?php
134
                                echo aui()->input(
135
                                    array(
136
                                        'type'        => 'text',
137
                                        'id'          => 'wpinv_company',
138
                                        'name'        => 'wpinv_company',
139
                                        'label'       => __( 'Company', 'invoicing' ),
140
                                        'label_type'  => 'vertical',
141
                                        'placeholder' => 'Acme Corporation',
142
                                        'class'       => 'form-control-sm',
143
                                        'value'       => $invoice->get_company( 'edit' ),
144
                                    )
145
                                );
146
                            ?>
147
                        </div>
148
                        <div class="col-12 col-sm-6">
149
                            <?php
150
                                echo aui()->input(
151
                                    array(
152
                                        'type'        => 'text',
153
                                        'id'          => 'wpinv_vat_number',
154
                                        'name'        => 'wpinv_vat_number',
155
                                        'label'       => __( 'Vat Number', 'invoicing' ),
156
                                        'label_type'  => 'vertical',
157
                                        'placeholder' => '1234567890',
158
                                        'class'       => 'form-control-sm',
159
                                        'value'       => $invoice->get_vat_number( 'edit' ),
160
                                    )
161
                                );
162
                            ?>
163
                        </div>
164
                    </div>
165
166
                    <div class="row">
167
                        <div class="col-12 col-sm-6">
168
                            <?php
169
                                echo aui()->input(
170
                                    array(
171
                                        'type'        => 'text',
172
                                        'id'          => 'wpinv_address',
173
                                        'name'        => 'wpinv_address',
174
                                        'label'       => __( 'Address', 'invoicing' ),
175
                                        'label_type'  => 'vertical',
176
                                        'placeholder' => 'Blekersdijk 295',
177
                                        'class'       => 'form-control-sm',
178
                                        'value'       => $invoice->get_address( 'edit' ),
179
                                    )
180
                                );
181
                            ?>
182
                        </div>
183
                        <div class="col-12 col-sm-6">
184
                            <?php
185
                                echo aui()->input(
186
                                    array(
187
                                        'type'        => 'text',
188
                                        'id'          => 'wpinv_city',
189
                                        'name'        => 'wpinv_city',
190
                                        'label'       => __( 'City', 'invoicing' ),
191
                                        'label_type'  => 'vertical',
192
                                        'placeholder' => 'Dolembreux',
193
                                        'class'       => 'form-control-sm',
194
                                        'value'       => $invoice->get_vat_number( 'edit' ),
195
                                    )
196
                                );
197
                            ?>
198
                        </div>
199
                    </div>
200
201
                    <div class="row">
202
                        <div class="col-12 col-sm-6">
203
                            <?php
204
                                echo aui()->select(
205
                                    array(
206
                                        'id'          => 'wpinv_country',
207
                                        'name'        => 'wpinv_country',
208
                                        'label'       => __( 'Country', 'invoicing' ),
209
                                        'label_type'  => 'vertical',
210
                                        'placeholder' => __( 'Choose a country', 'invoicing' ),
211
                                        'class'       => 'form-control-sm',
212
                                        'value'       => $invoice->get_country( 'edit' ),
213
                                        'options'     => wpinv_get_country_list(),
214
                                        'data-allow-clear' => 'false',
215
                                        'select2'          => true,
216
                                    )
217
                                );
218
                            ?>
219
                        </div>
220
                        <div class="col-12 col-sm-6">
221
                            <?php
222
223
                                $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
224
225
                                if ( empty( $states ) ) {
226
227
                                    echo aui()->input(
228
                                        array(
229
                                            'type'        => 'text',
230
                                            'id'          => 'wpinv_state',
231
                                            'name'        => 'wpinv_state',
232
                                            'label'       => __( 'State', 'invoicing' ),
233
                                            'label_type'  => 'vertical',
234
                                            'placeholder' => 'Liège',
235
                                            'class'       => 'form-control-sm',
236
                                            'value'       => $invoice->get_state( 'edit' ),
237
                                        )
238
                                    );
239
240
                                } else {
241
242
                                    echo aui()->select(
243
                                        array(
244
                                            'id'          => 'wpinv_state',
245
                                            'name'        => 'wpinv_state',
246
                                            'label'       => __( 'State', 'invoicing' ),
247
                                            'label_type'  => 'vertical',
248
                                            'placeholder' => __( 'Select a state', 'invoicing' ),
249
                                            'class'       => 'form-control-sm',
250
                                            'value'       => $invoice->get_state( 'edit' ),
251
                                            'options'     => $states,
252
                                            'data-allow-clear' => 'false',
253
                                            'select2'          => true,
254
                                        )
255
                                    );
256
257
                                }
258
                                
259
                            ?>
260
                        </div>
261
                    </div>
262
263
                    <div class="row">
264
                        <div class="col-12 col-sm-6">
265
                            <?php
266
                                echo aui()->input(
267
                                    array(
268
                                        'type'        => 'text',
269
                                        'id'          => 'wpinv_zip',
270
                                        'name'        => 'wpinv_zip',
271
                                        'label'       => __( 'Zip / Postal Code', 'invoicing' ),
272
                                        'label_type'  => 'vertical',
273
                                        'placeholder' => '4140',
274
                                        'class'       => 'form-control-sm',
275
                                        'value'       => $invoice->get_zip( 'edit' ),
276
                                    )
277
                                );
278
                            ?>
279
                        </div>
280
                        <div class="col-12 col-sm-6">
281
                            <?php
282
                                echo aui()->input(
283
                                    array(
284
                                        'type'        => 'text',
285
                                        'id'          => 'wpinv_phone',
286
                                        'name'        => 'wpinv_phone',
287
                                        'label'       => __( 'Phone', 'invoicing' ),
288
                                        'label_type'  => 'vertical',
289
                                        'placeholder' => '0493 18 45822',
290
                                        'class'       => 'form-control-sm',
291
                                        'value'       => $invoice->get_phone( 'edit' ),
292
                                    )
293
                                );
294
                            ?>
295
                        </div>
296
                    </div>
297
298
                </div>
299
            </div>
300
        <?php
301
    }
302
}
303