| Conditions | 9 |
| Paths | 16 |
| Total Lines | 147 |
| Code Lines | 114 |
| 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 |
||
| 143 | function form( $instance ) { |
||
| 144 | $defaults = array( |
||
| 145 | 'title' => 'Projects', |
||
| 146 | 'title_link' => '', |
||
| 147 | 'tagline' => '', |
||
| 148 | 'columns' => '3', |
||
| 149 | 'orderby' => 'name', |
||
| 150 | 'order' => 'ASC', |
||
| 151 | 'limit' => '', |
||
| 152 | 'include' => '', |
||
| 153 | 'display' => 'excerpt', |
||
| 154 | 'size' => 'lsx-thumbnail-single', |
||
| 155 | 'button_text' => '', |
||
| 156 | 'responsive' => 1, |
||
| 157 | 'show_image' => 1, |
||
| 158 | 'carousel' => 1, |
||
| 159 | 'featured' => 0, |
||
| 160 | ); |
||
| 161 | |||
| 162 | $instance = wp_parse_args( (array) $instance, $defaults ); |
||
| 163 | |||
| 164 | $title = esc_attr( $instance['title'] ); |
||
| 165 | $title_link = esc_attr( $instance['title_link'] ); |
||
| 166 | $tagline = esc_attr( $instance['tagline'] ); |
||
| 167 | $columns = esc_attr( $instance['columns'] ); |
||
| 168 | $orderby = esc_attr( $instance['orderby'] ); |
||
| 169 | $order = esc_attr( $instance['order'] ); |
||
| 170 | $limit = esc_attr( $instance['limit'] ); |
||
| 171 | $include = esc_attr( $instance['include'] ); |
||
| 172 | $display = esc_attr( $instance['display'] ); |
||
| 173 | $size = esc_attr( $instance['size'] ); |
||
| 174 | $button_text = esc_attr( $instance['button_text'] ); |
||
| 175 | $responsive = esc_attr( $instance['responsive'] ); |
||
| 176 | $show_image = esc_attr( $instance['show_image'] ); |
||
| 177 | $carousel = esc_attr( $instance['carousel'] ); |
||
| 178 | $featured = esc_attr( $instance['featured'] ); |
||
| 179 | ?> |
||
| 180 | <p> |
||
| 181 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'lsx-projects' ); ?></label> |
||
| 182 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> |
||
| 183 | </p> |
||
| 184 | <p> |
||
| 185 | <label for="<?php echo esc_attr( $this->get_field_id( 'title_link' ) ); ?>"><?php esc_html_e( 'Page Link:', 'lsx-projects' ); ?></label> |
||
| 186 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title_link' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title_link' ) ); ?>" type="text" value="<?php echo esc_attr( $title_link ); ?>" /> |
||
| 187 | <small><?php esc_html_e( 'Link the widget to a page', 'lsx-projects' ); ?></small> |
||
| 188 | </p> |
||
| 189 | <p> |
||
| 190 | <label for="<?php echo esc_attr( $this->get_field_id( 'tagline' ) ); ?>"><?php esc_html_e( 'Tagline:', 'lsx-projects' ); ?></label> |
||
| 191 | <textarea class="widefat" rows="8" cols="20" id="<?php echo esc_attr( $this->get_field_id( 'tagline' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'tagline' ) ); ?>"><?php echo esc_html( $tagline ); ?></textarea> |
||
| 192 | <small><?php esc_html_e( 'Tagline to display below the widget title', 'lsx-projects' ); ?></small> |
||
| 193 | </p> |
||
| 194 | <p> |
||
| 195 | <label for="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>"><?php esc_html_e( 'Columns:', 'lsx-projects' ); ?></label> |
||
| 196 | <select name="<?php echo esc_attr( $this->get_field_name( 'columns' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>" class="widefat"> |
||
| 197 | <?php |
||
| 198 | $options = array( '1', '2', '3', '4' ); |
||
| 199 | |||
| 200 | foreach ( $options as $option ) { |
||
| 201 | echo '<option value="' . esc_attr( lcfirst( $option ) ) . '" id="' . esc_attr( $option ) . '"', lcfirst( $option ) == $columns ? ' selected="selected"' : '', '>', esc_html( $option ), '</option>'; |
||
| 202 | } |
||
| 203 | ?> |
||
| 204 | </select> |
||
| 205 | </p> |
||
| 206 | <p> |
||
| 207 | <label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>"><?php esc_html_e( 'Order By:', 'lsx-projects' ); ?></label> |
||
| 208 | <select name="<?php echo esc_attr( $this->get_field_name( 'orderby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>" class="widefat"> |
||
| 209 | <?php |
||
| 210 | $options = array( |
||
| 211 | esc_html__( 'None', 'lsx-projects' ) => 'none', |
||
| 212 | esc_html__( 'ID', 'lsx-projects' ) => 'ID', |
||
| 213 | esc_html__( 'Name', 'lsx-projects' ) => 'name', |
||
| 214 | esc_html__( 'Date', 'lsx-projects' ) => 'date', |
||
| 215 | esc_html__( 'Modified Date', 'lsx-projects' ) => 'modified', |
||
| 216 | esc_html__( 'Random', 'lsx-projects' ) => 'rand', |
||
| 217 | esc_html__( 'Menu (WP dashboard order)', 'lsx-projects' ) => 'menu_order', |
||
| 218 | ); |
||
| 219 | |||
| 220 | foreach ( $options as $name => $value ) { |
||
| 221 | echo '<option value="' . esc_attr( $value ) . '" id="' . esc_attr( $value ) . '"', $orderby == $value ? ' selected="selected"' : '', '>', esc_html( $name ), '</option>'; |
||
| 222 | } |
||
| 223 | ?> |
||
| 224 | </select> |
||
| 225 | </p> |
||
| 226 | <p> |
||
| 227 | <label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>"><?php esc_html_e( 'Order:', 'lsx-projects' ); ?></label> |
||
| 228 | <select name="<?php echo esc_attr( $this->get_field_name( 'order' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>" class="widefat"> |
||
| 229 | <?php |
||
| 230 | $options = array( |
||
| 231 | esc_html__( 'Ascending', 'lsx-projects' ) => 'ASC', |
||
| 232 | esc_html__( 'Descending', 'lsx-projects' ) => 'DESC', |
||
| 233 | ); |
||
| 234 | |||
| 235 | foreach ( $options as $name => $value ) { |
||
| 236 | echo '<option value="' . esc_attr( $value ) . '" id="' . esc_attr( $value ) . '"', $order == $value ? ' selected="selected"' : '', '>', esc_html( $name ), '</option>'; |
||
| 237 | } |
||
| 238 | ?> |
||
| 239 | </select> |
||
| 240 | </p> |
||
| 241 | <p class="limit"> |
||
| 242 | <label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php esc_html_e( 'Maximum amount:', 'lsx-projects' ); ?></label> |
||
| 243 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" /> |
||
| 244 | <small><?php esc_html_e( 'Leave empty to display all', 'lsx-projects' ); ?></small> |
||
| 245 | </p> |
||
| 246 | <p> |
||
| 247 | <label for="<?php echo esc_attr( $this->get_field_id( 'include' ) ); ?>"><?php esc_html_e( 'Specify Projects by ID:', 'lsx-projects' ); ?></label> |
||
| 248 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'include' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'include' ) ); ?>" type="text" value="<?php echo esc_attr( $include ); ?>" /> |
||
| 249 | <small><?php esc_html_e( 'Comma separated list, overrides limit and order settings', 'lsx-projects' ); ?></small> |
||
| 250 | </p> |
||
| 251 | <p> |
||
| 252 | <label for="<?php echo esc_attr( $this->get_field_id( 'display' ) ); ?>"><?php esc_html_e( 'Display:', 'lsx-projects' ); ?></label> |
||
| 253 | <select name="<?php echo esc_attr( $this->get_field_name( 'display' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'display' ) ); ?>" class="widefat"> |
||
| 254 | <?php |
||
| 255 | $options = array( |
||
| 256 | esc_html__( 'Excerpt', 'lsx-projects' ) => 'excerpt', |
||
| 257 | esc_html__( 'Full Content', 'lsx-projects' ) => 'full', |
||
| 258 | ); |
||
| 259 | |||
| 260 | foreach ( $options as $name => $value ) { |
||
| 261 | echo '<option value="' . esc_attr( $value ) . '" id="' . esc_attr( $value ) . '"', $display == $value ? ' selected="selected"' : '', '>', esc_html( $name ), '</option>'; |
||
| 262 | } |
||
| 263 | ?> |
||
| 264 | </select> |
||
| 265 | </p> |
||
| 266 | <p> |
||
| 267 | <label for="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>"><?php esc_html_e( 'Image size:', 'lsx-projects' ); ?></label> |
||
| 268 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'size' ) ); ?>" type="text" value="<?php echo esc_attr( $size ); ?>" /> |
||
| 269 | </p> |
||
| 270 | <p> |
||
| 271 | <label for="<?php echo esc_attr( $this->get_field_id( 'button_text' ) ); ?>"><?php esc_html_e( 'Button "view all" text:', 'lsx-projects' ); ?></label> |
||
| 272 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'button_text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'button_text' ) ); ?>" type="text" value="<?php echo esc_attr( $button_text ); ?>" /> |
||
| 273 | <small><?php esc_html_e( 'Leave empty to not display the button', 'lsx-projects' ); ?></small> |
||
| 274 | </p> |
||
| 275 | <p> |
||
| 276 | <input id="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_image' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $show_image ); ?> /> |
||
| 277 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>"><?php esc_html_e( 'Display Images', 'lsx-projects' ); ?></label> |
||
| 278 | </p> |
||
| 279 | <p> |
||
| 280 | <input id="<?php echo esc_attr( $this->get_field_id( 'responsive' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'responsive' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $responsive ); ?> /> |
||
| 281 | <label for="<?php echo esc_attr( $this->get_field_id( 'responsive' ) ); ?>"><?php esc_html_e( 'Responsive Images', 'lsx-projects' ); ?></label> |
||
| 282 | </p> |
||
| 283 | <p> |
||
| 284 | <input id="<?php echo esc_attr( $this->get_field_id( 'carousel' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'carousel' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $carousel ); ?> /> |
||
| 285 | <label for="<?php echo esc_attr( $this->get_field_id( 'carousel' ) ); ?>"><?php esc_html_e( 'Carousel', 'lsx-projects' ); ?></label> |
||
| 286 | </p> |
||
| 287 | <p> |
||
| 288 | <input id="<?php echo esc_attr( $this->get_field_id( 'featured' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'featured' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $featured ); ?> /> |
||
| 289 | <label for="<?php echo esc_attr( $this->get_field_id( 'featured' ) ); ?>"><?php esc_html_e( 'Featured posts', 'lsx-projects' ); ?></label> |
||
| 290 | </p> |
||
| 300 |