Passed
Push — master ( d9c503...543c87 )
by Brian
13:46
created

WPInv_Meta_Box_Billing_Details::output()   C

Complexity

Conditions 8
Paths 32

Size

Total Lines 171
Code Lines 116

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 8
eloc 116
c 1
b 0
f 1
nc 32
nop 1
dl 0
loc 171
rs 6.7555

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
// MUST have WordPress.
3
if ( !defined( 'WPINC' ) ) {
4
    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
5
}
6
7
class WPInv_Meta_Box_Billing_Details {
8
    public static function output( $post ) {
9
        global $user_ID;
10
        $post_id    = !empty( $post->ID ) ? $post->ID : 0;
11
        $invoice    = new WPInv_Invoice( $post_id );
12
13
?>
14
<div class="gdmbx2-wrap form-table">
15
    <div id="gdmbx2-metabox-wpinv_address" class="gdmbx2-metabox gdmbx-field-list wpinv-address gdmbx-row">
16
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-user-id table-layout">
17
            <div class="gdmbx-th">
18
                <label for="post_author_override"><?php _e( 'Customer', 'invoicing' );?></label>
19
            </div>
20
            <div class="gdmbx-td gdmbx-customer-div">
21
            <?php wpinv_dropdown_users( array(
22
                            'name' => 'post_author_override',
23
                            'selected' => empty($post->ID) ? $user_ID : $post->post_author,
24
                            'include_selected' => true,
25
                            'show' => 'display_name_with_email',
26
                            'orderby' => 'user_email',
27
                            'class' => 'gdmbx2-text-large wpi_select2'
28
                        ) ); ?>
29
            </div>
30
        </div>
31
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-email table-layout" style="display:none">
32
            <div class="gdmbx-th"><label for="wpinv_email"><?php _e( 'Email', 'invoicing' );?> <span class="required">*</span></label>
33
            </div>
34
            <div class="gdmbx-td">
35
                <input type="hidden" id="wpinv_new_user" name="wpinv_new_user" value="" />
36
                <input type="email" class="gdmbx2-text-large" name="wpinv_email" id="wpinv_email" />
37
            </div>
38
        </div>
39
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-btns table-layout">
40
            <div class="gdmbx-th"><label><?php _e( 'Actions', 'invoicing' );?></label>
41
            </div>
42
            <?php if ( $invoice->has_status( array( 'auto-draft', 'draft', 'wpi-pending', 'wpi-quote-pending' ) ) ) { ?>
43
                <div class="gdmbx-td">
44
                    <a id="wpinv-fill-user-details" class="button button-small button-secondary" title="<?php esc_attr_e( 'Fill User Details', 'invoicing' );?>" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-refresh"></i><?php _e( 'Fill User Details', 'invoicing' );?></a>
45
                    <a class="wpinv-new-user button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-plus"></i><?php _e( 'Add New User', 'invoicing' );?></a>
46
                    <a style="display:none" class="wpinv-new-cancel button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-close"></i><?php _e( 'Cancel', 'invoicing' );?> </a>
47
                </div>
48
            <?php } ?>
49
        </div>
50
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-first-name table-layout">
51
            <div class="gdmbx-th"><label for="wpinv_first_name"><?php _e( 'First Name', 'invoicing' );?></label></div>
52
            <div class="gdmbx-td">
53
                <input type="text" class="gdmbx2-text-large" name="wpinv_first_name" id="wpinv_first_name" value="<?php echo esc_attr( $invoice->first_name );?>" />
54
            </div>
55
        </div>
56
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-last-name table-layout">
57
            <div class="gdmbx-th"><label for="wpinv_last_name"><?php _e( 'Last Name', 'invoicing' );?></label></div>
58
            <div class="gdmbx-td">
59
                <input type="text" class="gdmbx2-text-large" name="wpinv_last_name" id="wpinv_last_name" value="<?php echo esc_attr( $invoice->last_name );?>" />
60
            </div>
61
        </div>
62
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-company table-layout">
63
            <div class="gdmbx-th"><label for="wpinv_company"><?php _e( 'Company', 'invoicing' );?></label></div>
64
            <div class="gdmbx-td">
65
                <input type="text" class="gdmbx2-text-large" name="wpinv_company" id="wpinv_company" value="<?php echo esc_attr( $invoice->company );?>" />
66
            </div>
67
        </div>
68
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-vat-number table-layout">
69
            <div class="gdmbx-th"><label for="wpinv_vat_number"><?php _e( 'Vat Number', 'invoicing' );?></label></div>
70
            <div class="gdmbx-td">
71
                <input type="text" class="gdmbx2-text-large" name="wpinv_vat_number" id="wpinv_vat_number" value="<?php echo esc_attr( $invoice->vat_number );?>" />
72
            </div>
73
        </div>
74
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-address table-layout">
75
            <div class="gdmbx-th"><label for="wpinv_address"><?php _e( 'Address', 'invoicing' );?></label></div>
76
            <div class="gdmbx-td">
77
                <input type="text" class="gdmbx2-text-large" name="wpinv_address" id="wpinv_address" value="<?php echo esc_attr( $invoice->address );?>" />
78
            </div>
79
        </div>
80
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-city table-layout">
81
            <div class="gdmbx-th"><label for="wpinv_city"><?php _e( 'City', 'invoicing' );?></label></div>
82
            <div class="gdmbx-td">
83
                <input type="text" class="gdmbx2-text-large" name="wpinv_city" id="wpinv_city" value="<?php echo esc_attr( $invoice->city );?>" />
84
            </div>
85
        </div>
86
        <div class="gdmbx-row gdmbx-type-select gdmbx-wpinv-country table-layout">
87
            <div class="gdmbx-th"><label for="wpinv_country"><?php _e( 'Country', 'invoicing' );?> <span class="wpi-loader"><i class="fa fa-refresh fa-spin"></i></span></label></div>
88
            <div class="gdmbx-td">
89
                <?php
90
                echo wpinv_html_select( array(
91
                    'options'          => array_merge( array( '' => __( 'Choose a country', 'invoicing' ) ), wpinv_get_country_list() ),
92
                    'name'             => 'wpinv_country',
93
                    'id'               => 'wpinv_country',
94
                    'selected'         => $invoice->country,
95
                    'show_option_all'  => false,
96
                    'show_option_none' => false,
97
                    'class'            => 'gdmbx2-text-large wpi_select2',
98
                    'placeholder'      => __( 'Choose a country', 'invoicing' ),
99
                    'required'         => false,
100
                ) );
101
                ?>
102
            </div>
103
        </div>
104
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-state table-layout">
105
            <div class="gdmbx-th"><label for="wpinv_state"><?php _e( 'State', 'invoicing' );?></label></div>
106
            <div class="gdmbx-td">
107
                <?php
108
                $states = wpinv_get_country_states( $invoice->country );
109
                if( !empty( $states ) ) {
110
                    echo wpinv_html_select( array(
111
                        'options'          => array_merge( array( '' => __( 'Choose a state', 'invoicing' ) ), $states ),
112
                        'name'             => 'wpinv_state',
113
                        'id'               => 'wpinv_state',
114
                        'selected'         => $invoice->state,
115
                        'show_option_all'  => false,
116
                        'show_option_none' => false,
117
                        'class'            => 'gdmbx2-text-large wpi_select2',
118
                        'placeholder'      => __( 'Choose a state', 'invoicing' ),
119
                        'required'         => false,
120
                    ) );
121
                } else {
122
                    echo wpinv_html_text( array(
123
                        'name'  => 'wpinv_state',
124
                        'value' => ! empty( $invoice->state ) ? $invoice->state : '',
125
                        'id'    => 'wpinv_state',
126
                        'class' => 'gdmbx2-text-large',
127
                        'required' => false,
128
                    ) );
129
                }
130
                ?>
131
            </div>
132
        </div>
133
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-zip table-layout">
134
            <div class="gdmbx-th"><label for="wpinv_zip"><?php _e( 'Zipcode', 'invoicing' );?></label></div>
135
            <div class="gdmbx-td">
136
                <input type="text" class="gdmbx2-text-large" name="wpinv_zip" id="wpinv_zip" value="<?php echo esc_attr( $invoice->zip );?>" />
137
            </div>
138
        </div>
139
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-phone table-layout">
140
            <div class="gdmbx-th"><label for="wpinv_phone"><?php _e( 'Phone', 'invoicing' );?></label></div>
141
            <div class="gdmbx-td">
142
                <input type="text" class="gdmbx2-text-large" name="wpinv_phone" id="wpinv_phone" value="<?php echo esc_attr( $invoice->phone );?>" />
143
            </div>
144
        </div>
145
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-ip table-layout">
146
            <div class="gdmbx-th"><label for="wpinv_ip"><?php _e( 'IP Address', 'invoicing' );?><?php if ($invoice->ip) { ?>
147
                &nbsp;&nbsp;<a href="<?php echo admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $invoice->ip ); ?>" title="<?php esc_attr_e( 'View IP information', 'invoicing' );?>" target="_blank"><i class="fa fa-external-link" aria-hidden="true"></i></a>
148
                <?php } ?></label></div>
149
            <div class="gdmbx-td">
150
                <input type="text" class="gdmbx2-text-large" value="<?php echo esc_attr( $invoice->ip );?>" readonly />
151
            </div>
152
        </div>
153
154
        <?php if( ! $invoice->is_paid() ) { ?>
155
156
            <div class="gdmbx-row gdmbx-type-select gdmbx-wpinv-currency table-layout">
157
            <div class="gdmbx-th"><label for="wpinv_currency"><?php _e( 'Currency', 'invoicing' );?></label></div>
158
            <div class="gdmbx-td">
159
                <?php
160
                echo wpinv_html_select( array(
161
                    'options'          => array_merge( array( '' => __( 'Currency for the invoice', 'invoicing' ) ), wpinv_get_currencies() ),
162
                    'name'             => 'wpinv_currency',
163
                    'id'               => 'wpinv_currency',
164
                    'selected'         => $invoice->get_currency(),
165
                    'show_option_all'  => false,
166
                    'show_option_none' => false,
167
                    'class'            => 'gdmbx2-text-large wpi_select2',
168
                    'placeholder'      => __( 'Choose a currency', 'invoicing' ),
169
                    'required'         => true,
170
                ) );
171
                ?>
172
            </div>
173
        </div>
174
175
        <?php } ?>
176
    </div>
177
</div>
178
<?php wp_nonce_field( 'wpinv_save_invoice', 'wpinv_save_invoice' ) ;?>
179
<?php
180
    }
181
}
182