Conditions | 13 |
Paths | 160 |
Total Lines | 61 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
17 | function bd_build_query_options( $delete_options, $options = array() ) { |
||
18 | // private posts. |
||
19 | if ( isset( $delete_options['private'] ) ) { |
||
20 | if ( $delete_options['private'] ) { |
||
21 | $options['post_status'] = 'private'; |
||
22 | } else { |
||
23 | if ( ! isset( $options['post_status'] ) ) { |
||
24 | $options['post_status'] = 'publish'; |
||
25 | } |
||
26 | } |
||
27 | } |
||
28 | |||
29 | // limit to query. |
||
30 | if ( $delete_options['limit_to'] > 0 ) { |
||
31 | $options['showposts'] = $delete_options['limit_to']; |
||
32 | } else { |
||
33 | $options['nopaging'] = 'true'; |
||
34 | } |
||
35 | |||
36 | // post type. |
||
37 | if ( isset( $delete_options['post_type'] ) ) { |
||
38 | $options['post_type'] = $delete_options['post_type']; |
||
39 | } |
||
40 | |||
41 | // exclude sticky posts. |
||
42 | if ( isset( $delete_options['exclude_sticky'] ) && ( true === $delete_options['exclude_sticky'] ) ) { |
||
43 | $options['post__not_in'] = get_option( 'sticky_posts' ); |
||
44 | } |
||
45 | |||
46 | // date query. |
||
47 | if ( $delete_options['restrict'] ) { |
||
48 | if ( 'before' === $delete_options['date_op'] || 'after' === $delete_options['date_op'] ) { |
||
49 | $options['date_query'] = array( |
||
50 | array( |
||
51 | 'column' => 'post_date', |
||
52 | $delete_options['date_op'] => "{$delete_options['days']} day ago", |
||
53 | ), |
||
54 | ); |
||
55 | } elseif ( '=' === $delete_options['date_op'] ) { |
||
56 | $published_date = getdate( strtotime( $delete_options['pub_date'] ) ); |
||
57 | $options['date_query'] = [ |
||
58 | [ |
||
59 | 'year' => $published_date['year'], |
||
60 | 'month' => $published_date['mon'], |
||
61 | 'day' => $published_date['mday'], |
||
62 | ], |
||
63 | ]; |
||
64 | } elseif ( 'between' === $delete_options['date_op'] ) { |
||
65 | $published_date_start = date( 'Y-m-d', strtotime( $delete_options['pub_date_start'] ) ); |
||
66 | $published_date_end = date( 'Y-m-d', strtotime( $delete_options['pub_date_end'] ) ); |
||
67 | $options['date_query'] = [ |
||
68 | [ |
||
69 | 'after' => $published_date_start, |
||
70 | 'before' => $published_date_end, |
||
71 | 'inclusive' => true, |
||
72 | ], |
||
73 | ]; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | return $options; |
||
78 | } |
||
128 |