Conditions | 5 |
Paths | 6 |
Total Lines | 121 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
70 | public static function get_customer_invoice_data( $invoice ) { |
||
71 | |||
72 | // Prepare basic properties. |
||
73 | $props_to_export = array( |
||
74 | 'number' => array( |
||
75 | 'name' => __( 'Invoice Number', 'invoicing' ), |
||
76 | 'value' => $invoice->get_number(), |
||
77 | ), |
||
78 | 'created_date' => array( |
||
79 | 'name' => __( 'Created Date', 'invoicing' ), |
||
80 | 'value' => $invoice->get_date_created(), |
||
81 | ), |
||
82 | 'due_date' => array( |
||
83 | 'name' => __( 'Due Date', 'invoicing' ), |
||
84 | 'value' => $invoice->get_due_date(), |
||
85 | ), |
||
86 | 'items' => array( |
||
87 | 'name' => __( 'Invoice Items', 'invoicing' ), |
||
88 | 'value' => self::process_invoice_items( $invoice ), |
||
89 | ), |
||
90 | 'discount' => array( |
||
91 | 'name' => __( 'Invoice Discount', 'invoicing' ), |
||
92 | 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
||
93 | ), |
||
94 | 'total' => array( |
||
95 | 'name' => __( 'Invoice Total', 'invoicing' ), |
||
96 | 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
||
97 | ), |
||
98 | 'status' => array( |
||
99 | 'name' => __( 'Invoice Status', 'invoicing' ), |
||
100 | 'value' => $invoice->get_status_nicename(), |
||
101 | ), |
||
102 | 'first_name' => array( |
||
103 | 'name' => __( 'First Name', 'invoicing' ), |
||
104 | 'value' => $invoice->get_first_name(), |
||
105 | ), |
||
106 | 'last_name' => array( |
||
107 | 'name' => __( 'Last Name', 'invoicing' ), |
||
108 | 'value' => $invoice->get_last_name(), |
||
109 | ), |
||
110 | 'email' => array( |
||
111 | 'name' => __( 'Email Address', 'invoicing' ), |
||
112 | 'value' => $invoice->get_email(), |
||
113 | ), |
||
114 | 'company' => array( |
||
115 | 'name' => __( 'Company', 'invoicing' ), |
||
116 | 'value' => $invoice->get_company(), |
||
117 | ), |
||
118 | 'phone' => array( |
||
119 | 'name' => __( 'Phone Number', 'invoicing' ), |
||
120 | 'value' => $invoice->get_phone(), |
||
121 | ), |
||
122 | 'address' => array( |
||
123 | 'name' => __( 'Address', 'invoicing' ), |
||
124 | 'value' => $invoice->get_address(), |
||
125 | ), |
||
126 | 'city' => array( |
||
127 | 'name' => __( 'City', 'invoicing' ), |
||
128 | 'value' => $invoice->get_city(), |
||
129 | ), |
||
130 | 'state' => array( |
||
131 | 'name' => __( 'State', 'invoicing' ), |
||
132 | 'value' => $invoice->get_state(), |
||
133 | ), |
||
134 | 'zip' => array( |
||
135 | 'name' => __( 'Zip', 'invoicing' ), |
||
136 | 'value' => $invoice->get_zip(), |
||
137 | ), |
||
138 | 'vat_number' => array( |
||
139 | 'name' => __( 'VAT Number', 'invoicing' ), |
||
140 | 'value' => $invoice->get_vat_number(), |
||
141 | ), |
||
142 | 'description' => array( |
||
143 | 'name' => __( 'Description', 'invoicing' ), |
||
144 | 'value' => $invoice->get_description(), |
||
145 | ), |
||
146 | ); |
||
147 | |||
148 | // In case the invoice is paid, add the payment date and gateway. |
||
149 | if ( $invoice->is_paid() ) { |
||
150 | |||
151 | $props_to_export['completed_date'] = array( |
||
152 | 'name' => __( 'Completed Date', 'invoicing' ), |
||
153 | 'value' => $invoice->get_completed_date(), |
||
154 | ); |
||
155 | |||
156 | $props_to_export['gateway'] = array( |
||
157 | 'name' => __( 'Paid Via', 'invoicing' ), |
||
158 | 'value' => $invoice->get_gateway(), |
||
159 | ); |
||
160 | |||
161 | } |
||
162 | |||
163 | // Maybe add subscription details. |
||
164 | $props_to_export = self::process_subscription( $invoice, $props_to_export ); |
||
165 | |||
166 | // Add the ip address. |
||
167 | $props_to_export['ip'] = array( |
||
168 | 'name' => __( 'IP Address', 'invoicing' ), |
||
169 | 'value' => $invoice->get_ip(), |
||
170 | ); |
||
171 | |||
172 | // Add the invoice url. |
||
173 | $props_to_export['view_url'] = array( |
||
174 | 'name' => __( 'Invoice URL', 'invoicing' ), |
||
175 | 'value' => $invoice->get_view_url(), |
||
176 | ); |
||
177 | |||
178 | // Return the values. |
||
179 | $items = apply_filters( 'getpaid_privacy_export_invoice_personal_data', array_values( $props_to_export ), $invoice ); |
||
180 | |||
181 | $data = array(); |
||
182 | |||
183 | // Unset null values to prevent PHP deprecated notice. |
||
184 | foreach ( $items as $item ) { |
||
185 | if ( isset( $item['value'] ) && ! is_null( $item['value'] ) ) { |
||
186 | $data[] = $item; |
||
187 | } |
||
188 | } |
||
189 | |||
190 | return $data; |
||
191 | } |
||
269 |