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

GetPaid_Meta_Box_Invoice_Payment_Meta::output()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 181
Code Lines 131

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 131
c 1
b 0
f 0
dl 0
loc 181
rs 8
cc 3
nc 2
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 Payment Meta
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_Payment_Meta Class.
16
 */
17
class GetPaid_Meta_Box_Invoice_Payment_Meta {
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
        ?>
30
31
        <style>
32
            #wpinv-payment-meta label {
33
                margin-bottom: 3px;
34
                font-weight: 600;
35
            }
36
        </style>
37
                <div class="bsui" style="margin-top: 1.5rem">
38
39
                    <div id="gdmbx2-metabox-wpinv-payment-meta" class="wpinv-payment-meta">
40
                    <?php
41
42
                        // Invoice key.
43
                        echo aui()->input(
44
                            array(
45
                                'type'        => 'text',
46
                                'id'          => 'wpinv_key',
47
                                'name'        => 'wpinv_key',
48
                                'label'       => __( 'Invoice Key:', 'invoicing' ),
49
                                'label_type'  => 'vertical',
50
                                'class'       => 'form-control-sm',
51
                                'value'       => $invoice->get_key( 'edit' ),
52
                                'extra_attributes' => array(
53
                                    'onclick'  => 'this.select();',
54
                                    'readonly' => 'true',
55
                                ),
56
                            )
57
                        );
58
59
                        // View URL.
60
                        echo aui()->input(
61
                            array(
62
                                'type'        => 'text',
63
                                'id'          => 'wpinv_view_url',
64
                                'name'        => 'wpinv_view_url',
65
                                'label'       => __( 'Invoice URL:', 'invoicing' ),
66
                                'label_type'  => 'vertical',
67
                                'class'       => 'form-control-sm',
68
                                'value'       => $invoice->get_view_url(),
69
                                'extra_attributes' => array(
70
                                    'onclick'  => 'this.select();',
71
                                    'readonly' => 'true',
72
                                ),
73
                            )
74
                        );
75
76
                        // If the invoice is paid...
77
                        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
78
79
                            // Payment date.
80
                            echo aui()->input(
81
                                array(
82
                                    'type'        => 'datepicker',
83
                                    'id'          => 'wpinv_date_completed',
84
                                    'name'        => 'date_completed',
85
                                    'label'       => __( 'Payment Date:', 'invoicing' ),
86
                                    'label_type'  => 'vertical',
87
                                    'placeholder' => 'YYYY-MM-DD 00:00',
88
                                    'class'       => 'form-control-sm',
89
                                    'value'       => $invoice->get_date_completed( 'edit' ),
90
                                    'extra_attributes' => array(
91
                                        'data-enable-time' => 'true',
92
                                        'data-time_24hr'   => 'true',
93
                                        'data-allow-input' => 'true',
94
                                    ),
95
                                )
96
                            );
97
98
                            // Gateway.
99
                            echo aui()->input(
100
                                array(
101
                                    'type'        => 'text',
102
                                    'id'          => 'wpinv_gateway',
103
                                    'name'        => 'wpinv_gateway',
104
                                    'label'       => __( 'Gateway:', 'invoicing' ),
105
                                    'label_type'  => 'vertical',
106
                                    'class'       => 'form-control-sm',
107
                                    'value'       => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ),
108
                                    'extra_attributes' => array(
109
                                        'onclick'  => 'this.select();',
110
                                        'readonly' => 'true',
111
                                    ),
112
                                )
113
                            );
114
115
                            // Transaction ID.
116
                            echo aui()->input(
117
                                array(
118
                                    'type'        => 'text',
119
                                    'id'          => 'wpinv_transaction_id',
120
                                    'name'        => 'wpinv_transaction_id',
121
                                    'label'       => __( 'Transaction ID:', 'invoicing' ),
122
                                    'label_type'  => 'vertical',
123
                                    'class'       => 'form-control-sm',
124
                                    'value'       => $invoice->get_transaction_id( 'edit' ),
125
                                    'help_text'   => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), $invoice->get_transaction_id(), $invoice ),
126
                                    'extra_attributes' => array(
127
                                        'onclick'  => 'this.select();',
128
                                        'readonly' => 'true',
129
                                    ),
130
                                )
131
                            );
132
133
                            // Currency.
134
                            echo aui()->input(
135
                                array(
136
                                    'type'        => 'text',
137
                                    'id'          => 'wpinv_currency',
138
                                    'name'        => 'wpinv_currency',
139
                                    'label'       => __( 'Currency:', 'invoicing' ),
140
                                    'label_type'  => 'vertical',
141
                                    'class'       => 'form-control-sm',
142
                                    'value'       => $invoice->get_currency( 'edit' ),
143
                                    'extra_attributes' => array(
144
                                        'onclick'  => 'this.select();',
145
                                        'readonly' => 'true',
146
                                    ),
147
                                )
148
                            );
149
150
                        } else {
151
152
                            // Payment URL.
153
                            echo aui()->input(
154
                                array(
155
                                    'type'        => 'text',
156
                                    'id'          => 'wpinv_payment_url',
157
                                    'name'        => 'wpinv_payment_url',
158
                                    'label'       => __( 'Payment URL:', 'invoicing' ),
159
                                    'label_type'  => 'vertical',
160
                                    'class'       => 'form-control-sm',
161
                                    'value'       => $invoice->get_checkout_payment_url(),
162
                                    'extra_attributes' => array(
163
                                        'onclick'  => 'this.select();',
164
                                        'readonly' => 'true',
165
                                    ),
166
                                )
167
                            );
168
169
                            // Set gateway.
170
                            echo aui()->select(
171
                                array(
172
                                    'id'               => 'wpinv_gateway',
173
                                    'name'             => 'wpinv_gateway',
174
                                    'label'            => __( 'Gateway:', 'invoicing' ),
175
                                    'label_type'       => 'vertical',
176
                                    'placeholder'      => __( 'Select Gateway', 'invoicing' ),
177
                                    'value'            => $invoice->get_gateway( 'edit' ),
178
                                    'select2'          => true,
179
                                    'data-allow-clear' => 'false',
180
                                    'options'          => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ),
181
                                )
182
                            );
183
184
                            // Set currency.
185
                            echo aui()->select(
186
                                array(
187
                                    'id'          => 'wpinv_currency',
188
                                    'name'        => 'wpinv_currency',
189
                                    'label'       => __( 'Currency', 'invoicing' ),
190
                                    'label_type'  => 'vertical',
191
                                    'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
192
                                    'class'       => 'form-control-sm',
193
                                    'value'       => $invoice->get_currency( 'edit' ),
194
                                    'required'    => false,
195
                                    'data-allow-clear' => 'false',
196
                                    'select2'          => true,
197
                                    'options'     => wpinv_get_currencies(),
198
                                )
199
                            );
200
201
                        }
202
203
                    ?>
204
                    </div>
205
                </div>
206
207
        <?php
208
    }
209
}
210