Conditions | 17 |
Paths | 95 |
Total Lines | 97 |
Code Lines | 74 |
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 |
||
68 | public static function get_customer_invoice_data( $invoice ) { |
||
69 | $personal_data = array(); |
||
70 | |||
71 | $props_to_export = array( |
||
72 | 'number' => __( 'Invoice Number', 'invoicing' ), |
||
73 | 'created_date' => __( 'Invoice Date', 'invoicing' ), |
||
74 | 'status' => __( 'Invoice Status', 'invoicing' ), |
||
75 | 'total' => __( 'Invoice Total', 'invoicing' ), |
||
76 | 'items' => __( 'Invoice Items', 'invoicing' ), |
||
77 | 'first_name' => __( 'First Name', 'invoicing' ), |
||
78 | 'last_name' => __( 'Last Name', 'invoicing' ), |
||
79 | 'email' => __( 'Email Address', 'invoicing' ), |
||
80 | '_wpinv_company' => __( 'Company', 'invoicing' ), |
||
81 | 'phone' => __( 'Phone Number', 'invoicing' ), |
||
82 | 'address' => __( 'Address', 'invoicing' ), |
||
83 | '_wpinv_city' => __( 'City', 'invoicing' ), |
||
84 | '_wpinv_country' => __( 'Country', 'invoicing' ), |
||
85 | '_wpinv_state' => __( 'State', 'invoicing' ), |
||
86 | '_wpinv_zip' => __( 'Zip Code', 'invoicing' ), |
||
87 | ); |
||
88 | |||
89 | $subscription = wpinv_get_subscription( $invoice ); |
||
90 | $period = $initial_amt = $bill_times = $billed = $renewal_date = ''; |
||
91 | |||
92 | if ( $invoice->is_recurring() && !empty( $subscription ) ) { |
||
93 | $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period,$subscription->frequency ); |
||
94 | $period = wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
||
95 | $initial_amt = wpinv_price( wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
||
96 | $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); |
||
97 | $renewal_date = ! empty( $subscription->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration ) ) : __( 'N/A', 'invoicing' ); |
||
98 | |||
99 | $props_to_export['period'] = __( 'Billing Cycle', 'invoicing' ); |
||
100 | $props_to_export['initial_amount'] = __( 'Initial Amount', 'invoicing' ); |
||
101 | $props_to_export['bill_times'] = __( 'Times Billed', 'invoicing' ); |
||
102 | $props_to_export['renewal_date'] = __( 'Renewal Date', 'invoicing' ); |
||
103 | } |
||
104 | |||
105 | $props_to_export['ip'] = __( 'IP Address', 'invoicing' ); |
||
106 | $props_to_export['view_url'] = __( 'Invoice Link', 'invoicing' ); |
||
107 | |||
108 | $props_to_export = apply_filters( 'wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
||
109 | |||
110 | foreach ( $props_to_export as $prop => $name ) { |
||
111 | $value = ''; |
||
112 | |||
113 | switch ( $prop ) { |
||
114 | case 'items': |
||
115 | $item_names = array(); |
||
116 | foreach ( $invoice->get_cart_details() as $key => $cart_item ) { |
||
117 | $item_quantity = $cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
||
118 | $item_names[] = $cart_item['name'] . ' x ' . $item_quantity; |
||
119 | } |
||
120 | $value = implode( ', ', $item_names ); |
||
121 | break; |
||
122 | case 'status': |
||
123 | $value = $invoice->get_status(true); |
||
124 | break; |
||
125 | case 'total': |
||
126 | $value = $invoice->get_total(true); |
||
127 | break; |
||
128 | case 'period': |
||
129 | $value = $period; |
||
130 | break; |
||
131 | case 'initial_amount': |
||
132 | $value = $initial_amt; |
||
133 | break; |
||
134 | case 'bill_times': |
||
135 | $value = $bill_times; |
||
136 | break; |
||
137 | case 'renewal_date': |
||
138 | $value = $renewal_date; |
||
139 | break; |
||
140 | default: |
||
141 | if ( is_callable( array( $invoice, 'get_' . $prop ) ) ) { |
||
142 | $value = $invoice->{"get_$prop"}(); |
||
143 | } else { |
||
144 | $value = $invoice->get_meta($prop); |
||
145 | } |
||
146 | break; |
||
147 | } |
||
148 | |||
149 | $value = apply_filters( 'wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice ); |
||
150 | |||
151 | if ( $value ) { |
||
152 | $personal_data[] = array( |
||
153 | 'name' => $name, |
||
154 | 'value' => $value, |
||
155 | ); |
||
156 | } |
||
157 | |||
158 | } |
||
159 | |||
160 | $personal_data = apply_filters( 'wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice ); |
||
161 | |||
162 | return $personal_data; |
||
163 | |||
164 | } |
||
165 | |||
167 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.