Conditions | 6 |
Paths | 32 |
Total Lines | 97 |
Code Lines | 82 |
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 |
||
24 | public function prepare_response( $object, $context ) { |
||
25 | $data = array( |
||
26 | 'id' => $object->get_id(), |
||
27 | 'name' => $object->get_name( $context ), |
||
28 | 'slug' => $object->get_slug( $context ), |
||
29 | 'permalink' => $object->get_permalink(), |
||
30 | 'date_created' => wc_rest_prepare_date_response( $object->get_date_created( $context ), false ), |
||
31 | 'date_created_gmt' => wc_rest_prepare_date_response( $object->get_date_created( $context ) ), |
||
32 | 'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified( $context ), false ), |
||
33 | 'date_modified_gmt' => wc_rest_prepare_date_response( $object->get_date_modified( $context ) ), |
||
34 | 'type' => $object->get_type(), |
||
35 | 'status' => $object->get_status( $context ), |
||
36 | 'featured' => $object->is_featured(), |
||
37 | 'catalog_visibility' => $object->get_catalog_visibility( $context ), |
||
38 | 'description' => $object->get_description( $context ), |
||
39 | 'short_description' => $object->get_short_description( $context ), |
||
40 | 'sku' => $object->get_sku( $context ), |
||
41 | 'price' => $object->get_price( $context ), |
||
42 | 'regular_price' => $object->get_regular_price( $context ), |
||
43 | 'sale_price' => $object->get_sale_price( $context ) ? $object->get_sale_price( $context ) : '', |
||
44 | 'date_on_sale_from' => wc_rest_prepare_date_response( $object->get_date_on_sale_from( $context ), false ), |
||
45 | 'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from( $context ) ), |
||
46 | 'date_on_sale_to' => wc_rest_prepare_date_response( $object->get_date_on_sale_to( $context ), false ), |
||
47 | 'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_to( $context ) ), |
||
48 | 'price_html' => $object->get_price_html(), |
||
49 | 'on_sale' => $object->is_on_sale( $context ), |
||
50 | 'purchasable' => $object->is_purchasable(), |
||
51 | 'total_sales' => $object->get_total_sales( $context ), |
||
52 | 'virtual' => $object->is_virtual(), |
||
53 | 'downloadable' => $object->is_downloadable(), |
||
54 | 'downloads' => $this->prepare_downloads( $object ), |
||
55 | 'download_limit' => $object->get_download_limit( $context ), |
||
56 | 'download_expiry' => $object->get_download_expiry( $context ), |
||
57 | 'external_url' => '', |
||
58 | 'button_text' => '', |
||
59 | 'tax_status' => $object->get_tax_status( $context ), |
||
60 | 'tax_class' => $object->get_tax_class( $context ), |
||
61 | 'manage_stock' => $object->managing_stock(), |
||
62 | 'stock_quantity' => $object->get_stock_quantity( $context ), |
||
63 | 'stock_status' => $object->get_stock_status( $context ), |
||
64 | 'backorders' => $object->get_backorders( $context ), |
||
65 | 'backorders_allowed' => $object->backorders_allowed(), |
||
66 | 'backordered' => $object->is_on_backorder(), |
||
67 | 'sold_individually' => $object->is_sold_individually(), |
||
68 | 'weight' => $object->get_weight( $context ), |
||
69 | 'dimensions' => array( |
||
70 | 'length' => $object->get_length( $context ), |
||
71 | 'width' => $object->get_width( $context ), |
||
72 | 'height' => $object->get_height( $context ), |
||
73 | ), |
||
74 | 'shipping_required' => $object->needs_shipping(), |
||
75 | 'shipping_taxable' => $object->is_shipping_taxable(), |
||
76 | 'shipping_class' => $object->get_shipping_class(), |
||
77 | 'shipping_class_id' => $object->get_shipping_class_id( $context ), |
||
78 | 'reviews_allowed' => $object->get_reviews_allowed( $context ), |
||
79 | 'average_rating' => $object->get_average_rating( $context ), |
||
80 | 'rating_count' => $object->get_rating_count(), |
||
81 | 'related_ids' => wp_parse_id_list( wc_get_related_products( $object->get_id() ) ), |
||
82 | 'upsell_ids' => wp_parse_id_list( $object->get_upsell_ids( $context ) ), |
||
83 | 'cross_sell_ids' => wp_parse_id_list( $object->get_cross_sell_ids( $context ) ), |
||
84 | 'parent_id' => $object->get_parent_id( $context ), |
||
85 | 'purchase_note' => $object->get_purchase_note( $context ), |
||
86 | 'categories' => $this->prepare_taxonomy_terms( $object ), |
||
87 | 'tags' => $this->prepare_taxonomy_terms( $object, 'tag' ), |
||
88 | 'images' => $this->prepare_images( $object ), |
||
89 | 'attributes' => $this->prepare_attributes( $object ), |
||
90 | 'default_attributes' => $this->prepare_default_attributes( $object ), |
||
91 | 'variations' => array(), |
||
92 | 'grouped_products' => array(), |
||
93 | 'menu_order' => $object->get_menu_order( $context ), |
||
94 | 'meta_data' => $object->get_meta_data(), |
||
95 | ); |
||
96 | |||
97 | // Add variations to variable products. |
||
98 | if ( $object->is_type( 'variable' ) ) { |
||
99 | $data['variations'] = $object->get_children(); |
||
100 | } |
||
101 | |||
102 | // Add grouped products data. |
||
103 | if ( $object->is_type( 'grouped' ) ) { |
||
104 | $data['grouped_products'] = $object->get_children(); |
||
105 | } |
||
106 | |||
107 | // Add external product data. |
||
108 | if ( $object->is_type( 'external' ) ) { |
||
109 | $data['external_url'] = $object->get_product_url( $context ); |
||
110 | $data['button_text'] = $object->get_button_text( $context ); |
||
111 | } |
||
112 | |||
113 | if ( 'view' === $context ) { |
||
114 | $data['description'] = wpautop( do_shortcode( $data['description'] ) ); |
||
115 | $data['short_description'] = apply_filters( 'woocommerce_short_description', $data['short_description'] ); |
||
116 | $data['average_rating'] = wc_format_decimal( $data['average_rating'], 2 ); |
||
117 | $data['purchase_note'] = wpautop( do_shortcode( $data['purchase_note'] ) ); |
||
118 | } |
||
119 | |||
120 | return $data; |
||
121 | } |
||
355 |
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.