| Conditions | 7 |
| Paths | 48 |
| Total Lines | 83 |
| Code Lines | 64 |
| 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 |
||
| 47 | public function prepare_response( $object, $context ) { |
||
| 48 | $data = $object->get_data(); |
||
| 49 | $format_decimal = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' ); |
||
| 50 | $format_date = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' ); |
||
| 51 | $format_line_items = array( 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines' ); |
||
| 52 | |||
| 53 | // Format decimal values. |
||
| 54 | foreach ( $format_decimal as $key ) { |
||
| 55 | $data[ $key ] = wc_format_decimal( $data[ $key ], $this->dp ); |
||
| 56 | } |
||
| 57 | |||
| 58 | // Format date values. |
||
| 59 | foreach ( $format_date as $key ) { |
||
| 60 | $datetime = $data[ $key ]; |
||
| 61 | $data[ $key ] = wc_rest_prepare_date_response( $datetime, false ); |
||
| 62 | $data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime ); |
||
| 63 | } |
||
| 64 | |||
| 65 | // Format the order status. |
||
| 66 | $data['status'] = 'wc-' === substr( $data['status'], 0, 3 ) ? substr( $data['status'], 3 ) : $data['status']; |
||
| 67 | |||
| 68 | // Format line items. |
||
| 69 | foreach ( $format_line_items as $key ) { |
||
| 70 | $data[ $key ] = array_values( array_map( array( $this, 'prepare_order_item_data' ), $data[ $key ] ) ); |
||
| 71 | } |
||
| 72 | |||
| 73 | // Refunds. |
||
| 74 | $data['refunds'] = array(); |
||
| 75 | foreach ( $object->get_refunds() as $refund ) { |
||
| 76 | $data['refunds'][] = array( |
||
| 77 | 'id' => $refund->get_id(), |
||
| 78 | 'reason' => $refund->get_reason() ? $refund->get_reason() : '', |
||
| 79 | 'total' => '-' . wc_format_decimal( $refund->get_amount(), $this->dp ), |
||
| 80 | ); |
||
| 81 | } |
||
| 82 | |||
| 83 | // Currency symbols. |
||
| 84 | $currency_symbol = get_woocommerce_currency_symbol( $data['currency'] ); |
||
| 85 | $data['currency_symbol'] = html_entity_decode( $currency_symbol ); |
||
| 86 | |||
| 87 | return array( |
||
| 88 | 'id' => $object->get_id(), |
||
| 89 | 'parent_id' => $data['parent_id'], |
||
| 90 | 'number' => $data['number'], |
||
| 91 | 'order_key' => $data['order_key'], |
||
| 92 | 'created_via' => $data['created_via'], |
||
| 93 | 'version' => $data['version'], |
||
| 94 | 'status' => $data['status'], |
||
| 95 | 'currency' => $data['currency'], |
||
| 96 | 'currency_symbol' => $data['currency_symbol'], |
||
| 97 | 'date_created' => $data['date_created'], |
||
| 98 | 'date_created_gmt' => $data['date_created_gmt'], |
||
| 99 | 'date_modified' => $data['date_modified'], |
||
| 100 | 'date_modified_gmt' => $data['date_modified_gmt'], |
||
| 101 | 'discount_total' => $data['discount_total'], |
||
| 102 | 'discount_tax' => $data['discount_tax'], |
||
| 103 | 'shipping_total' => $data['shipping_total'], |
||
| 104 | 'shipping_tax' => $data['shipping_tax'], |
||
| 105 | 'cart_tax' => $data['cart_tax'], |
||
| 106 | 'total' => $data['total'], |
||
| 107 | 'total_tax' => $data['total_tax'], |
||
| 108 | 'prices_include_tax' => $data['prices_include_tax'], |
||
| 109 | 'customer_id' => $data['customer_id'], |
||
| 110 | 'customer_ip_address' => $data['customer_ip_address'], |
||
| 111 | 'customer_user_agent' => $data['customer_user_agent'], |
||
| 112 | 'customer_note' => $data['customer_note'], |
||
| 113 | 'billing' => $data['billing'], |
||
| 114 | 'shipping' => $data['shipping'], |
||
| 115 | 'payment_method' => $data['payment_method'], |
||
| 116 | 'payment_method_title' => $data['payment_method_title'], |
||
| 117 | 'transaction_id' => $data['transaction_id'], |
||
| 118 | 'date_paid' => $data['date_paid'], |
||
| 119 | 'date_paid_gmt' => $data['date_paid_gmt'], |
||
| 120 | 'date_completed' => $data['date_completed'], |
||
| 121 | 'date_completed_gmt' => $data['date_completed_gmt'], |
||
| 122 | 'cart_hash' => $data['cart_hash'], |
||
| 123 | 'meta_data' => $data['meta_data'], |
||
| 124 | 'line_items' => $data['line_items'], |
||
| 125 | 'tax_lines' => $data['tax_lines'], |
||
| 126 | 'shipping_lines' => $data['shipping_lines'], |
||
| 127 | 'fee_lines' => $data['fee_lines'], |
||
| 128 | 'coupon_lines' => $data['coupon_lines'], |
||
| 129 | 'refunds' => $data['refunds'], |
||
| 130 | ); |
||
| 184 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.