| Conditions | 9 |
| Paths | 8 |
| Total Lines | 78 |
| Code Lines | 52 |
| 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 |
||
| 109 | public function render( $atts ) { |
||
| 110 | |||
| 111 | //extract attributes and set default values |
||
| 112 | $settings = shortcode_atts( array( |
||
| 113 | 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, |
||
| 114 | 'height' => NULL, |
||
| 115 | 'width' => NULL, |
||
| 116 | 'is_embed' => FALSE, |
||
| 117 | 'hash_bookmark' => FALSE, |
||
| 118 | 'default_bg_color' => 'white', |
||
| 119 | 'scale_factor' => 2, |
||
| 120 | 'initial_zoom' => NULL, |
||
| 121 | 'zoom_sequence' => '[0.5, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]', |
||
| 122 | 'timenav_position' => 'bottom', |
||
| 123 | 'optimal_tick_width' => 100, |
||
| 124 | 'base_class' => 'tl-timeline', |
||
| 125 | 'timenav_height' => 150, |
||
| 126 | 'timenav_height_percentage' => NULL, |
||
| 127 | 'timenav_mobile_height_percentage' => 40, |
||
| 128 | 'timenav_height_min' => 150, |
||
| 129 | 'marker_height_min' => 30, |
||
| 130 | 'marker_width_min' => 100, |
||
| 131 | 'marker_padding' => 5, |
||
| 132 | 'start_at_slide' => 0, |
||
| 133 | 'start_at_end' => FALSE, |
||
| 134 | 'menubar_height' => 0, |
||
| 135 | 'use_bc' => FALSE, |
||
| 136 | 'duration' => 1000, |
||
| 137 | 'ease' => 'TL.Ease.easeInOutQuint', |
||
| 138 | 'slide_default_fade' => '0%', |
||
| 139 | 'language' => $this->get_locale(), |
||
| 140 | 'ga_property_id' => NULL, |
||
| 141 | 'track_events' => "['back_to_start','nav_next','nav_previous','zoom_in','zoom_out']", |
||
| 142 | 'global' => FALSE, |
||
| 143 | // The following settings are unrelated to TimelineJS script. |
||
| 144 | 'display_images_as' => 'media', |
||
| 145 | 'excerpt_length' => 55, |
||
| 146 | ), $atts ); |
||
| 147 | |||
| 148 | // Load the TimelineJS stylesheets and scripts. |
||
| 149 | wp_enqueue_style( 'timelinejs', dirname( plugin_dir_url( __FILE__ ) ) . '/timelinejs/css/timeline.css' ); |
||
| 150 | wp_enqueue_script( 'timelinejs', dirname( plugin_dir_url( __FILE__ ) ) . '/timelinejs/js/timeline' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '-min' : '' ) . '.js' ); |
||
| 151 | |||
| 152 | // Enqueue the scripts for the timeline. |
||
| 153 | $this->enqueue_scripts(); |
||
| 154 | |||
| 155 | // Provide the script with options. |
||
| 156 | wp_localize_script( 'timelinejs', 'wl_timeline_params', array( |
||
| 157 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
||
| 158 | // TODO: this parameter is already provided by WP |
||
| 159 | 'action' => 'wl_timeline', |
||
| 160 | // These settings apply to our wl_timeline AJAX endpoint. |
||
| 161 | 'display_images_as' => $settings['display_images_as'], |
||
| 162 | 'excerpt_length' => $settings['excerpt_length'], |
||
| 163 | // These settings apply to the timeline javascript client. |
||
| 164 | 'settings' => array_filter( $settings, function ( $value ) { |
||
| 165 | // Do not set NULL values. |
||
| 166 | return ( NULL !== $value ); |
||
| 167 | } ) |
||
| 168 | ) ); |
||
| 169 | |||
| 170 | // Get the current post id or set null if global is set to true. |
||
| 171 | $post_id = ( $settings['global'] ? NULL : get_the_ID() ); |
||
| 172 | |||
| 173 | // Escaping atts. |
||
| 174 | $style = sprintf( 'style="%s%s"', isset( $settings['width'] ) ? "width:{$settings['width']};" : '', isset( $settings['height'] ) ? "height:{$settings['height']};" : '' ); |
||
| 175 | $data_post_id = ( isset( $post_id ) ? "data-post-id='$post_id'" : '' ); |
||
| 176 | |||
| 177 | // Generate a unique ID for this timeline. |
||
| 178 | $element_id = uniqid( 'wl-timeline-' ); |
||
| 179 | |||
| 180 | if ( WP_DEBUG ) { |
||
| 181 | $this->log_service->trace( "Creating a timeline widget [ element id :: $element_id ][ post id :: $post_id ]" ); |
||
| 182 | } |
||
| 183 | |||
| 184 | // Building template. |
||
| 185 | return sprintf( '<div class="wl-timeline-container" %s><div class="wl-timeline" id="%s" %s></div></div>', $style, $element_id, $data_post_id ); |
||
| 186 | } |
||
| 187 | |||
| 205 |