| Conditions | 15 |
| Paths | 60 |
| Total Lines | 62 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 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 |
||
| 33 | public function widget( $args, $instance ) { |
||
| 34 | |||
| 35 | extract( $args ); |
||
|
|
|||
| 36 | |||
| 37 | // Create fancy collapser |
||
| 38 | $fancy_collapser = ''; |
||
| 39 | if ( $instance['show_sliding_cart'] == 1 ) { |
||
| 40 | if ( isset($_SESSION['slider_state']) && is_numeric( $_SESSION['slider_state'] ) ) { |
||
| 41 | if ( $_SESSION['slider_state'] == 0 ) { |
||
| 42 | $collapser_image = 'plus.png'; |
||
| 43 | } else { |
||
| 44 | $collapser_image = 'minus.png'; |
||
| 45 | } |
||
| 46 | $fancy_collapser = ' <a href="#" onclick="return shopping_cart_collapser()" id="fancy_collapser_link"><img src="' . WPSC_CORE_IMAGES_URL . '/' . $collapser_image . '" title="" alt="" id="fancy_collapser" /></a>'; |
||
| 47 | } else { |
||
| 48 | if ( ! wpsc_get_customer_meta( 'nzshpcart' ) ) { |
||
| 49 | $collapser_image = 'plus.png'; |
||
| 50 | } else { |
||
| 51 | $collapser_image = 'minus.png'; |
||
| 52 | } |
||
| 53 | $fancy_collapser = ' <a href="#" onclick="return shopping_cart_collapser()" id="fancy_collapser_link"><img src="' . WPSC_CORE_IMAGES_URL . '/' . $collapser_image . '" title="" alt="" id="fancy_collapser" /></a>'; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | // Start widget output |
||
| 58 | $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Shopping Cart', 'wp-e-commerce' ) : $instance['title'] ); |
||
| 59 | echo $before_widget; |
||
| 60 | |||
| 61 | if ( $title ) |
||
| 62 | echo $before_title . $title . $fancy_collapser . $after_title; |
||
| 63 | |||
| 64 | // Set display state |
||
| 65 | $display_state = ''; |
||
| 66 | if ( ( ( isset( $_SESSION['slider_state'] ) && ( $_SESSION['slider_state'] == 0 ) ) || ( wpsc_cart_item_count() < 1 ) ) && ( get_option( 'show_sliding_cart' ) == 1 ) ) |
||
| 67 | $display_state = 'style="display: none;"'; |
||
| 68 | |||
| 69 | // Output start, if we are not allowed to save results ( WPSC_DONT_CACHE ) load the cart using ajax |
||
| 70 | $use_object_frame = false; |
||
| 71 | if ( WPSC_PAGE_CACHE_IN_USE ) { |
||
| 72 | echo '<div id="sliding_cart" class="shopping-cart-wrapper">'; |
||
| 73 | if ( ( strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) == false ) && ( $use_object_frame == true ) ) { |
||
| 74 | ?> |
||
| 75 | <object codetype="text/html" type="text/html" data="index.php?wpsc_action=cart_html_page" border="0"> |
||
| 76 | <p><?php _e( 'Loading...', 'wp-e-commerce' ); ?></p> |
||
| 77 | </object> |
||
| 78 | <?php |
||
| 79 | } else { |
||
| 80 | ?> |
||
| 81 | <div class="wpsc_cart_loading"><p><?php _e( 'Loading...', 'wp-e-commerce' ); ?></p></div> |
||
| 82 | <?php |
||
| 83 | } |
||
| 84 | echo '</div>'; |
||
| 85 | } else { |
||
| 86 | echo '<div id="sliding_cart" class="shopping-cart-wrapper" ' . $display_state . '>'; |
||
| 87 | include( wpsc_get_template_file_path( 'wpsc-cart_widget.php' ) ); |
||
| 88 | echo '</div>'; |
||
| 89 | } |
||
| 90 | |||
| 91 | // End widget output |
||
| 92 | echo $after_widget; |
||
| 93 | |||
| 94 | } |
||
| 95 | |||
| 151 |