Conditions | 16 |
Paths | 256 |
Total Lines | 307 |
Code Lines | 198 |
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 |
||
79 | public function add_settings_meta_calendar_panel( $post_id ) { |
||
80 | |||
81 | ?> |
||
82 | <table id="default-calendar-settings"> |
||
83 | <thead> |
||
84 | <tr><th colspan="2"><?php _e( 'Default Calendar', 'google-calendar-events' ); ?></th></tr> |
||
85 | </thead> |
||
86 | <tbody class="simcal-panel-section"> |
||
87 | |||
88 | <tr class="simcal-panel-field simcal-default-calendar-grid" style="display: none;"> |
||
89 | <th><label for="_default_calendar_event_bubbles_action"><?php _e( 'Event Bubbles', 'google-calendar-events' ); ?></label></th> |
||
90 | <td> |
||
91 | <?php |
||
92 | |||
93 | $bubbles = get_post_meta( $post_id, '_default_calendar_event_bubble_trigger', true ); |
||
94 | |||
95 | simcal_print_field( array( |
||
96 | 'type' => 'radio', |
||
97 | 'inline' => 'inline', |
||
98 | 'name' => '_default_calendar_event_bubble_trigger', |
||
99 | 'id' => '_default_calendar_event_bubble_trigger', |
||
100 | 'tooltip' => __( 'Open event bubbles in calendar grid by clicking or hovering on event titles. On mobile devices it will always default to tapping.', 'google-calendar-events' ), |
||
101 | 'value' => $bubbles ? $bubbles : 'hover', |
||
102 | 'default' => 'hover', |
||
103 | 'options' => array( |
||
104 | 'click' => __( 'Click', 'google-calendar-events' ), |
||
105 | 'hover' => __( 'Hover', 'google-calendar-events' ), |
||
106 | ), |
||
107 | ) ); |
||
108 | |||
109 | ?> |
||
110 | </td> |
||
111 | </tr> |
||
112 | <tr class="simcal-panel-field simcal-default-calendar-grid" style="display: none;"> |
||
113 | <th><label for="_default_calendar_trim_titles"><?php _e( 'Trim Event Titles', 'google-calendar-events' ); ?></label></th> |
||
114 | <td> |
||
115 | <?php |
||
116 | |||
117 | $trim = get_post_meta( $post_id, '_default_calendar_trim_titles', true ); |
||
118 | |||
119 | simcal_print_field( array( |
||
120 | 'type' => 'checkbox', |
||
121 | 'name' => '_default_calendar_trim_titles', |
||
122 | 'id' => '_default_calendar_trim_titles', |
||
123 | 'class' => array( |
||
124 | 'simcal-field-show-next', |
||
125 | ), |
||
126 | 'value' => 'yes' == $trim ? 'yes' : 'no', |
||
127 | 'attributes' => array( |
||
128 | 'data-show-next-if-value' => 'yes', |
||
129 | ), |
||
130 | ) ); |
||
131 | |||
132 | simcal_print_field( array( |
||
133 | 'type' => 'standard', |
||
134 | 'subtype' => 'number', |
||
135 | 'name' => '_default_calendar_trim_titles_chars', |
||
136 | 'id' => '_default_calendar_trim_titles_chars', |
||
137 | 'tooltip' => __( 'Shorten event titles in calendar grid to a specified length in characters.', 'google-calendar-events' ), |
||
138 | 'class' => array( |
||
139 | 'simcal-field-tiny', |
||
140 | ), |
||
141 | 'value' => 'yes' == $trim ? strval( max( absint( get_post_meta( $post_id, '_default_calendar_trim_titles_chars', true ) ), 1 ) ) : '20', |
||
142 | 'attributes' => array( |
||
143 | 'min' => '1', |
||
144 | ), |
||
145 | ) ); |
||
146 | |||
147 | ?> |
||
148 | </td> |
||
149 | </tr> |
||
150 | <tr class="simcal-panel-field simcal-default-calendar-list" style="display: none;"> |
||
151 | <th><label for="_default_calendar_list_grouped_span"><?php _e( 'Span', 'google-calendar-events' ); ?></label></th> |
||
152 | <td> |
||
153 | <?php |
||
154 | |||
155 | $list_span = max( absint( get_post_meta( $post_id, '_default_calendar_list_range_span', true ) ), 1 ); |
||
156 | |||
157 | simcal_print_field( array( |
||
158 | 'type' => 'standard', |
||
159 | 'subtype' => 'number', |
||
160 | 'name' => '_default_calendar_list_range_span', |
||
161 | 'id' => '_default_calendar_list_range_span', |
||
162 | 'class' => array( |
||
163 | 'simcal-field-tiny', |
||
164 | 'simcal-field-inline', |
||
165 | ), |
||
166 | 'value' => strval( $list_span ), |
||
167 | 'attributes' => array( |
||
168 | 'min' => '1', |
||
169 | ), |
||
170 | ) ); |
||
171 | |||
172 | $list_type = get_post_meta( $post_id, '_default_calendar_list_range_type', true ); |
||
173 | |||
174 | simcal_print_field( array( |
||
175 | 'type' => 'select', |
||
176 | 'name' => '_default_calendar_list_range_type', |
||
177 | 'id' => '_default_calendar_list_range_type', |
||
178 | 'tooltip' => __( 'Range of events to show on each calendar page.', 'google-calendar-events' ), |
||
179 | 'class' => array( |
||
180 | 'simcal-field-inline', |
||
181 | ), |
||
182 | 'value' => $list_type, |
||
183 | 'options' => array( |
||
184 | 'monthly' => __( 'Month(s)', 'google-calendar-events' ), |
||
185 | 'weekly' => __( 'Week(s)', 'google-calendar-events' ), |
||
186 | 'daily' => __( 'Day(s)', 'google-calendar-events' ), |
||
187 | 'events' => __( 'Event(s)', 'google-calendar-events' ), |
||
188 | ), |
||
189 | ) ); |
||
190 | |||
191 | ?> |
||
192 | </td> |
||
193 | </tr> |
||
194 | <tr class="simcal-panel-field simcal-default-calendar-list" style="display: none;"> |
||
195 | <th><label for="_default_calendar_list_header"><?php _e( 'Hide Header', 'google-calendar-events' ); ?></label></th> |
||
196 | <td> |
||
197 | <?php |
||
198 | |||
199 | $header = get_post_meta( $post_id, '_default_calendar_list_header', true ); |
||
200 | |||
201 | simcal_print_field( array( |
||
202 | 'type' => 'checkbox', |
||
203 | 'name' => '_default_calendar_list_header', |
||
204 | 'id' => '_default_calendar_list_header', |
||
205 | 'tooltip' => __( 'You can use this to hide the month header for this calendar.', 'google-calendar-events' ), |
||
206 | 'value' => 'yes' == $header ? 'yes' : 'no', |
||
207 | ) ); |
||
208 | |||
209 | ?> |
||
210 | </td> |
||
211 | </tr> |
||
212 | <tr class="simcal-panel-field simcal-default-calendar-list" style="display: none;"> |
||
213 | <th><label for="_default_calendar_compact_list"><?php _e( 'Compact List', 'google-calendar-events' ); ?></label></th> |
||
214 | <td> |
||
215 | <?php |
||
216 | |||
217 | $compact = get_post_meta( $post_id, '_default_calendar_compact_list', true ); |
||
218 | |||
219 | simcal_print_field( array( |
||
220 | 'type' => 'checkbox', |
||
221 | 'name' => '_default_calendar_compact_list', |
||
222 | 'id' => '_default_calendar_compact_list', |
||
223 | 'tooltip' => __( 'Make an events list more compact by grouping together events from different days in a single list.', 'google-calendar-events' ), |
||
224 | 'value' => 'yes' == $compact ? 'yes' : 'no', |
||
225 | ) ); |
||
226 | |||
227 | ?> |
||
228 | </td> |
||
229 | </tr> |
||
230 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
||
231 | <th><label for="_default_calendar_limit_visible_events"><?php _e( 'Limit Visible Events', 'google-calendar-events' ); ?></label></th> |
||
232 | <td> |
||
233 | <?php |
||
234 | |||
235 | $limit = get_post_meta( $post_id, '_default_calendar_limit_visible_events', true ); |
||
236 | |||
237 | simcal_print_field( array( |
||
238 | 'type' => 'checkbox', |
||
239 | 'name' => '_default_calendar_limit_visible_events', |
||
240 | 'id' => '_default_calendar_limit_visible_events', |
||
241 | 'value' => 'yes' == $limit ? 'yes' : 'no', |
||
242 | 'class' => array( |
||
243 | 'simcal-field-show-next', |
||
244 | ), |
||
245 | 'attributes' => array( |
||
246 | 'data-show-next-if-value' => 'yes', |
||
247 | ) |
||
248 | ) ); |
||
249 | |||
250 | $visible_events = absint( get_post_meta( $post_id, '_default_calendar_visible_events', true ) ); |
||
251 | $visible_events = $visible_events > 0 ? $visible_events : 3; |
||
252 | |||
253 | simcal_print_field( array( |
||
254 | 'type' => 'standard', |
||
255 | 'subtype' => 'number', |
||
256 | 'name' => '_default_calendar_visible_events', |
||
257 | 'id' => '_default_calendar_visible_events', |
||
258 | 'tooltip' => __( 'Limit the number of initial visible events on each day to a set maximum.', 'google-calendar-events' ), |
||
259 | 'class' => array( |
||
260 | 'simcal-field-tiny', |
||
261 | ), |
||
262 | 'value' => $visible_events, |
||
263 | 'attributes' => array( |
||
264 | 'min' => '1', |
||
265 | ) |
||
266 | ) ); |
||
267 | |||
268 | ?> |
||
269 | </td> |
||
270 | </tr> |
||
271 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
||
272 | <th><label for="_default_calendar_event_bubbles_action"><?php _e( 'Expand Multi-day Events', 'google-calendar-events' ); ?></label></th> |
||
273 | <td> |
||
274 | <?php |
||
275 | |||
276 | $post_meta = get_post_meta( $post_id ); |
||
277 | |||
278 | if ( ! is_array( $post_meta ) && ! empty( $post_meta ) ) { |
||
279 | $multi_day_value = 'current_day_only'; |
||
280 | } else { |
||
281 | $multi_day_value = get_post_meta( $post_id, '_default_calendar_expand_multi_day_events', true ); |
||
282 | } |
||
283 | |||
284 | simcal_print_field( array( |
||
285 | 'type' => 'select', |
||
286 | 'name' => '_default_calendar_expand_multi_day_events', |
||
287 | 'id' => '_default_calendar_expand_multi_day_events', |
||
288 | 'tooltip' => __( 'For events spanning multiple days, you can display them on each day of the event, ' . |
||
289 | 'only on the first day of the event, or on all days of the event, but only up to the current day. ' . |
||
290 | 'Third option applies to list views only.', 'google-calendar-events' ), |
||
291 | 'value' => $multi_day_value, |
||
292 | 'options' => array( |
||
293 | 'yes' => __( 'Yes, display on all days of event', 'google-calendar-events' ), |
||
294 | 'no' => __( 'No, display only on first day of event', 'google-calendar-events' ), |
||
295 | 'current_day_only' => __( 'No, display on all days of event up to current day (list view only)', 'google-calendar-events' ), |
||
296 | ), |
||
297 | 'default' => 'yes', |
||
298 | ) ); |
||
299 | |||
300 | ?> |
||
301 | </td> |
||
302 | </tr> |
||
303 | </tbody> |
||
304 | <?php |
||
305 | |||
306 | // TODO Defaults repeated here and in process_meta(). Need to consolidate at some point. |
||
307 | $settings = get_option( 'simple-calendar_settings_calendars' ); |
||
308 | $default_theme = isset( $settings['default-calendar']['theme'] ) ? $settings['default-calendar']['theme'] : 'light'; |
||
309 | $default_today_color = isset( $settings['default-calendar']['today_color'] ) ? $settings['default-calendar']['today_color'] : '#1e73be'; |
||
310 | $default_days_events_color = isset( $settings['default-calendar']['days_events_color'] ) ? $settings['default-calendar']['days_events_color'] : '#000000'; |
||
311 | |||
312 | ?> |
||
313 | <tbody class="simcal-panel-section"> |
||
314 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
||
315 | <th><label for="_default_calendar_style_theme"><?php _e( 'Theme', 'google-calendar-events' ); ?></label></th> |
||
316 | <td> |
||
317 | <?php |
||
318 | |||
319 | $saved = get_post_meta( $post_id, '_default_calendar_style_theme', true ); |
||
320 | $value = ! $saved ? $default_theme : $saved; |
||
321 | |||
322 | simcal_print_field( array( |
||
323 | 'type' => 'select', |
||
324 | 'name' => '_default_calendar_style_theme', |
||
325 | 'id' => '_default_calendar_style_theme', |
||
326 | 'value' => $value, |
||
327 | 'tooltip' => __( 'Choose a calendar theme to match your site theme.', 'google-calendar-events' ), |
||
328 | 'options' => array( |
||
329 | 'light' => __( 'Light', 'google-calendar-events' ), |
||
330 | 'dark' => __( 'Dark', 'google-calendar-events' ), |
||
331 | ), |
||
332 | ) ); |
||
333 | |||
334 | ?> |
||
335 | </td> |
||
336 | </tr> |
||
337 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
||
338 | <th><label for="_default_calendar_style_today"><?php _e( 'Today', 'google-calendar-events' ); ?></label></th> |
||
339 | <td> |
||
340 | <?php |
||
341 | |||
342 | $saved = get_post_meta( $post_id, '_default_calendar_style_today', true ); |
||
343 | $value = ! $saved ? $default_today_color : $saved; |
||
344 | |||
345 | simcal_print_field( array( |
||
346 | 'type' => 'standard', |
||
347 | 'subtype' => 'color-picker', |
||
348 | 'name' => '_default_calendar_style_today', |
||
349 | 'id' => '_default_calendar_style_today', |
||
350 | 'value' => $value, |
||
351 | 'tooltip' => __( "This option will set the background color for today's date. It will change the day number background and the border around the current day.", 'google-calendar-events' ), |
||
352 | ) ); |
||
353 | |||
354 | ?> |
||
355 | </td> |
||
356 | </tr> |
||
357 | <tr class="simcal-panel-field simcal-default-calendar-grid simcal-default-calendar-list" style="display: none;"> |
||
358 | <th><label for="_default_calendar_style_days_events"><?php _e( 'Days with Events', 'google-calendar-events' ); ?></label></th> |
||
359 | <td> |
||
360 | <?php |
||
361 | |||
362 | $saved = get_post_meta( $post_id, '_default_calendar_style_days_events', true ); |
||
363 | $value = ! $saved ? $default_days_events_color : $saved; |
||
364 | |||
365 | simcal_print_field( array( |
||
366 | 'type' => 'standard', |
||
367 | 'subtype' => 'color-picker', |
||
368 | 'name' => '_default_calendar_style_days_events', |
||
369 | 'id' => '_default_calendar_style_days_events', |
||
370 | 'value' => $value, |
||
371 | 'tooltip' => __( 'This setting will modify the day number background for any days that have events on them.', 'google-calendar-events' ), |
||
372 | ) ); |
||
373 | |||
374 | ?> |
||
375 | </td> |
||
376 | </tr> |
||
377 | |||
378 | </tbody> |
||
379 | <?php |
||
380 | |||
381 | ?> |
||
382 | </table> |
||
383 | <?php |
||
384 | |||
385 | } |
||
386 | |||
447 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.