| Conditions | 11 |
| Paths | 6 |
| Total Lines | 34 |
| 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 |
||
| 39 | function lsx_wetu_get_post_count( $post_type = '', $post_status = '' ) { |
||
| 40 | global $wpdb; |
||
| 41 | $count = '0'; |
||
| 42 | if ( '' !== $post_type && '' !== $post_status ) { |
||
| 43 | $result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`ID`) FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) ); |
||
| 44 | if ( false !== $result && '' !== $result ) { |
||
| 45 | if ( 'tour' === $post_type ) { |
||
| 46 | $wetu_tours = get_transient( 'lsx_ti_tours' ); |
||
| 47 | if ( false !== $wetu_tours ) { |
||
| 48 | $results = $wpdb->get_results( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) ); |
||
| 49 | $result_count = 0; |
||
| 50 | $tour_wetu_ids = array(); |
||
| 51 | foreach ( $wetu_tours as $wetu_tour ) { |
||
| 52 | $tour_wetu_ids[] = $wetu_tour['identifier']; |
||
| 53 | } |
||
| 54 | |||
| 55 | if ( ! empty( $results ) ) { |
||
| 56 | foreach ( $results as $tour ) { |
||
| 57 | $current_wetu_id = get_post_meta( $tour->ID, 'lsx_wetu_id', true ); |
||
| 58 | if ( in_array( $current_wetu_id, $tour_wetu_ids ) ) { |
||
| 59 | $result_count++; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | $result = $result_count; |
||
| 64 | } else { |
||
| 65 | $result = 0; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | $count = $result; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | return $count; |
||
| 72 | } |
||
| 73 | |||
| 103 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.