Conditions | 11 |
Paths | 48 |
Total Lines | 47 |
Code Lines | 29 |
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 |
||
45 | public function process_date_fields( $delete_options ) { |
||
46 | if ( ! empty( $delete_options['relative_date'] ) && 'custom' !== $delete_options['relative_date'] ) { |
||
47 | $delete_options['meta_value'] = date( 'c', strtotime( $delete_options['relative_date'] ) ); |
||
48 | } |
||
49 | |||
50 | if ( ! empty( $delete_options['date_unit'] ) && ! empty( $delete_options['date_type'] ) ) { |
||
51 | $interval_unit = $delete_options['date_unit']; |
||
52 | $interval_type = $delete_options['date_type']; |
||
53 | |||
54 | switch ( $delete_options['meta_op'] ) { |
||
55 | case '<': |
||
56 | case '<=': |
||
57 | $delete_options['meta_value'] = date( 'Y-m-d', strtotime( '-' . $interval_unit . ' ' . $interval_type ) ); |
||
58 | break; |
||
59 | default: |
||
60 | $delete_options['meta_value'] = date( 'Y-m-d', strtotime( $interval_unit . ' ' . $interval_type ) ); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | // In v1.0 `date_format` was changed to `meta_value_date_format`. |
||
65 | // Needed? |
||
66 | if ( isset( $delete_options['date_format'] ) ) { |
||
67 | $delete_options['meta_value_date_format'] = $delete_options['date_format']; |
||
68 | } |
||
69 | $meta_query = array( |
||
70 | 'key' => $delete_options['meta_key'], |
||
71 | 'value' => $delete_options['meta_value'], |
||
72 | 'compare' => $delete_options['meta_op'], |
||
73 | 'type' => $delete_options['meta_type'], |
||
74 | ); |
||
75 | |||
76 | $options = array( |
||
77 | 'meta_query' => array( $meta_query ), |
||
78 | ); |
||
79 | |||
80 | if ( 'DATE' === $meta_query['type'] && ! empty( $delete_options['meta_value_date_format'] ) ) { |
||
81 | $options['cf_meta_value_date_format'] = $delete_options['meta_value_date_format']; |
||
82 | |||
83 | if ( ! empty( $delete_options['input_value_date_format'] ) ) { |
||
84 | $options['cf_input_value_date_format'] = $delete_options['input_value_date_format']; |
||
85 | } else { |
||
86 | $options['cf_input_value_date_format'] = '%Y-%m-%d'; |
||
87 | } |
||
88 | |||
89 | $this->load(); |
||
90 | } |
||
91 | return $options; |
||
92 | } |
||
160 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.