Passed
Push — master ( 169dfd...f76276 )
by Stiofan
04:33
created

WPInv_Meta_Box_Billing_Details::output()   C

Complexity

Conditions 7
Paths 16

Size

Total Lines 151
Code Lines 86

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 86
nc 16
nop 1
dl 0
loc 151
rs 6.4589
c 0
b 0
f 0

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
<div class="gdmbx2-wrap form-table">
14
    <div id="gdmbx2-metabox-wpinv_address" class="gdmbx2-metabox gdmbx-field-list wpinv-address gdmbx-row">
15
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-user-id table-layout">
16
            <div class="gdmbx-th">
17
                <label for="post_author_override"><?php _e( 'Customer', 'invoicing' );?></label>
18
            </div>
19
            <div class="gdmbx-td gdmbx-customer-div">
20
            <?php wpinv_dropdown_users( array(
0 ignored issues
show
Documentation introduced by
array('name' => 'post_au...=> 'gdmbx2-text-large') is of type array<string,?,{"name":"...ing","class":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
21
                            'name' => 'post_author_override',
22
                            'selected' => empty($post->ID) ? $user_ID : $post->post_author,
23
                            'include_selected' => true,
24
                            'show' => 'user_email',
25
                            'orderby' => 'user_email',
26
                            'class' => 'gdmbx2-text-large'
27
                        ) ); ?>
28
            </div>
29
        </div>
30
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-email table-layout" style="display:none">
31
            <div class="gdmbx-th"><label for="wpinv_email"><?php _e( 'Email', 'invoicing' );?> <span class="required">*</span></label>
32
            </div>
33
            <div class="gdmbx-td">
34
                <input type="hidden" id="wpinv_new_user" name="wpinv_new_user" value="" />
35
                <input type="email" class="gdmbx2-text-large" name="wpinv_email" id="wpinv_email" />
36
            </div>
37
        </div>
38
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-btns table-layout">
39
            <div class="gdmbx-th"><label><?php _e( 'Actions', 'invoicing' );?></label>
40
            </div>
41
            <?php if($invoice->has_status(array('wpi-pending', 'wpi-quote-pending'))){ ?>
42
                <div class="gdmbx-td">
43
                    <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>
44
                    <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>
45
                    <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>
46
                </div>
47
            <?php } ?>
48
        </div>
49
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-first-name table-layout">
50
            <div class="gdmbx-th"><label for="wpinv_first_name"><?php _e( 'First Name', 'invoicing' );?></label></div>
51
            <div class="gdmbx-td">
52
                <input type="text" class="gdmbx2-text-large" name="wpinv_first_name" id="wpinv_first_name" value="<?php echo esc_attr( $invoice->first_name );?>" />
53
            </div>
54
        </div>
55
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-last-name table-layout">
56
            <div class="gdmbx-th"><label for="wpinv_last_name"><?php _e( 'Last Name', 'invoicing' );?></label></div>
57
            <div class="gdmbx-td">
58
                <input type="text" class="gdmbx2-text-large" name="wpinv_last_name" id="wpinv_last_name" value="<?php echo esc_attr( $invoice->last_name );?>" />
59
            </div>
60
        </div>
61
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-company table-layout">
62
            <div class="gdmbx-th"><label for="wpinv_company"><?php _e( 'Company', 'invoicing' );?></label></div>
63
            <div class="gdmbx-td">
64
                <input type="text" class="gdmbx2-text-large" name="wpinv_company" id="wpinv_company" value="<?php echo esc_attr( $invoice->company );?>" />
65
            </div>
66
        </div>
67
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-vat-number table-layout">
68
            <div class="gdmbx-th"><label for="wpinv_vat_number"><?php _e( 'Vat Number', 'invoicing' );?></label></div>
69
            <div class="gdmbx-td">
70
                <input type="text" class="gdmbx2-text-large" name="wpinv_vat_number" id="wpinv_vat_number" value="<?php echo esc_attr( $invoice->vat_number );?>" />
71
            </div>
72
        </div>
73
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-address table-layout">
74
            <div class="gdmbx-th"><label for="wpinv_address"><?php _e( 'Address', 'invoicing' );?></label></div>
75
            <div class="gdmbx-td">
76
                <input type="text" class="gdmbx2-text-large" name="wpinv_address" id="wpinv_address" value="<?php echo esc_attr( $invoice->address );?>" />
77
            </div>
78
        </div>
79
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-city table-layout">
80
            <div class="gdmbx-th"><label for="wpinv_city"><?php _e( 'City', 'invoicing' );?></label></div>
81
            <div class="gdmbx-td">
82
                <input type="text" class="gdmbx2-text-large" name="wpinv_city" id="wpinv_city" value="<?php echo esc_attr( $invoice->city );?>" />
83
            </div>
84
        </div>
85
        <div class="gdmbx-row gdmbx-type-select gdmbx-wpinv-country table-layout">
86
            <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>
87
            <div class="gdmbx-td">
88
                <?php
89
                echo wpinv_html_select( array(
90
                    'options'          => array_merge( array( '' => __( 'Choose a country', 'invoicing' ) ), wpinv_get_country_list() ),
91
                    'name'             => 'wpinv_country',
92
                    'id'               => 'wpinv_country',
93
                    'selected'         => $invoice->country,
94
                    'show_option_all'  => false,
95
                    'show_option_none' => false,
96
                    'class'            => 'gdmbx2-text-large',
97
                    'chosen'           => false,
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',
118
                        'chosen'           => false,
119
                        'placeholder'      => __( 'Choose a state', 'invoicing' ),
120
                        'required'         => false,
121
                    ) );
122
                } else {
123
                    echo wpinv_html_text( array(
124
                        'name'  => 'wpinv_state',
125
                        'value' => ! empty( $invoice->state ) ? $invoice->state : '',
126
                        'id'    => 'wpinv_state',
127
                        'class' => 'gdmbx2-text-large',
128
                        'required' => false,
129
                    ) );
130
                }
131
                ?>
132
            </div>
133
        </div>
134
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-zip table-layout">
135
            <div class="gdmbx-th"><label for="wpinv_zip"><?php _e( 'Zipcode', 'invoicing' );?></label></div>
136
            <div class="gdmbx-td">
137
                <input type="text" class="gdmbx2-text-large" name="wpinv_zip" id="wpinv_zip" value="<?php echo esc_attr( $invoice->zip );?>" />
138
            </div>
139
        </div>
140
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-phone table-layout">
141
            <div class="gdmbx-th"><label for="wpinv_phone"><?php _e( 'Phone', 'invoicing' );?></label></div>
142
            <div class="gdmbx-td">
143
                <input type="text" class="gdmbx2-text-large" name="wpinv_phone" id="wpinv_phone" value="<?php echo esc_attr( $invoice->phone );?>" />
144
            </div>
145
        </div>
146
        <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-ip table-layout">
147
            <div class="gdmbx-th"><label for="wpinv_ip"><?php _e( 'IP Address', 'invoicing' );?><?php if ($invoice->ip) { ?>
148
                &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>
149
                <?php } ?></label></div>
150
            <div class="gdmbx-td">
151
                <input type="text" class="gdmbx2-text-large" value="<?php echo esc_attr( $invoice->ip );?>" readonly />
152
            </div>
153
        </div>
154
    </div>
155
</div>
156
<?php wp_nonce_field( 'wpinv_save_invoice', 'wpinv_save_invoice' ) ;?>
157
<?php
158
    }
159
}
160