| Conditions | 11 |
| Paths | 64 |
| Total Lines | 54 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 142 | protected function column_items( $item, $key ) { |
||
| 143 | $product = get_post( $item->product_id ); |
||
| 144 | $product_name = $item->product_name; |
||
| 145 | |||
| 146 | if ( $product->post_parent ) { |
||
| 147 | $permalink = wpsc_get_product_permalink( $product->post_parent ); |
||
| 148 | $product_name = get_post_field( 'post_title', $product->post_parent ); |
||
| 149 | } else { |
||
| 150 | $permalink = wpsc_get_product_permalink( $item->product_id ); |
||
| 151 | } |
||
| 152 | |||
| 153 | $variations = array(); |
||
| 154 | |||
| 155 | if ( is_array( $item->variation_values ) ) { |
||
| 156 | foreach ( $item->variation_values as $variation_set => $variation ) { |
||
| 157 | $set_name = get_term_field( 'name', $variation_set, 'wpsc-variation' ); |
||
| 158 | $variation_name = get_term_field( 'name', $variation , 'wpsc-variation' ); |
||
| 159 | |||
| 160 | if ( ! is_wp_error( $set_name ) && ! is_wp_error( $variation_name ) ) { |
||
| 161 | $variations[] = '<span>' . esc_html( $set_name ) . ':</span> ' . esc_html( $variation_name ); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | $variations = implode( ', ', $variations ); |
||
| 167 | |||
| 168 | $separator = ''; |
||
| 169 | |||
| 170 | if ( ! empty( $variations ) && ! empty( $item->sku ) ) { |
||
| 171 | $separator = ' | '; |
||
| 172 | } |
||
| 173 | |||
| 174 | ?> |
||
| 175 | <div class="wpsc-cart-item-description"> |
||
| 176 | <div class="wpsc-cart-item-title"> |
||
| 177 | <strong><a href="<?php echo $permalink; ?>"><?php echo esc_html( $product_name ); ?></a></strong> |
||
| 178 | </div> |
||
| 179 | <div class="wpsc-cart-item-details"> |
||
| 180 | <?php if ( ! empty( $item->sku ) ) : ?> |
||
| 181 | <span class="wpsc-cart-item-sku"><span><?php esc_html_e( 'SKU', 'wp-e-commerce' ); ?>:</span> <?php echo esc_html( $item->sku ); ?></span> |
||
| 182 | <?php endif ?> |
||
| 183 | |||
| 184 | <?php if ( $separator ) : ?> |
||
| 185 | <span class="separator"><?php echo $separator; ?></span> |
||
| 186 | <?php endif ?> |
||
| 187 | |||
| 188 | <?php if ( ! empty( $variations ) ) : ?> |
||
| 189 | <span class="wpsc-cart-item-variations"><?php echo $variations; ?></span> |
||
| 190 | <?php endif ?> |
||
| 191 | </div> |
||
| 192 | <?php $this->cart_item_description( $item, $key ); ?> |
||
| 193 | </div> |
||
| 194 | <?php |
||
| 195 | } |
||
| 196 | |||
| 213 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.