Conditions | 2 |
Paths | 2 |
Total Lines | 106 |
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 |
||
208 | function form( $instance ) { |
||
209 | $defaults = array( |
||
210 | 'title' => '', |
||
211 | 'href' => '', |
||
212 | 'width' => $this->default_width, |
||
213 | 'layout' => $this->default_layout, |
||
214 | 'theme' => $this->default_theme, |
||
215 | 'show_coverphoto' => true, |
||
216 | 'show_photo' => true, |
||
217 | 'show_owners' => false, |
||
218 | 'show_tagline' => true, |
||
219 | 'type' => $this->default_type, |
||
220 | ); |
||
221 | |||
222 | $instance = wp_parse_args( $instance, $defaults ); |
||
223 | ?> |
||
224 | |||
225 | <p> |
||
226 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"> |
||
227 | <?php _e( 'Title', 'jetpack' ); ?> |
||
228 | <input type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" id="<?php echo $this->get_field_id( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" /> |
||
229 | </label> |
||
230 | </p> |
||
231 | |||
232 | <p> |
||
233 | <label for="<?php echo $this->get_field_id( 'type' ); ?>"> |
||
234 | <?php _e( 'Type of Widget', 'jetpack' ); ?> |
||
235 | <select name="<?php echo $this->get_field_name( 'type' ); ?>" id="<?php echo $this->get_field_id( 'type' ); ?>" class="widefat googleplus-badge-choose-type"> |
||
236 | <?php |
||
237 | foreach ( $this->allowed_types as $type_value => $type_display ) { |
||
238 | printf( |
||
239 | '<option value="%s"%s>%s</option>', |
||
240 | esc_attr( $type_value ), |
||
241 | selected( $type_value, $instance['type'], false ), |
||
242 | esc_attr( $type_display ) |
||
243 | ); |
||
244 | } |
||
245 | ?> |
||
246 | </select> |
||
247 | </label> |
||
248 | </p> |
||
249 | |||
250 | <p> |
||
251 | <label for="<?php echo $this->get_field_id( 'href' ); ?>"> |
||
252 | <?php _e( 'Google+ URL', 'jetpack' ); ?> |
||
253 | <input type="text" name="<?php echo $this->get_field_name( 'href' ); ?>" id="<?php echo $this->get_field_id( 'href' ); ?>" value="<?php echo esc_url( $instance['href'] ); ?>" class="widefat" /> |
||
254 | </label> |
||
255 | </p> |
||
256 | |||
257 | <p> |
||
258 | <label for="<?php echo $this->get_field_id( 'width' ); ?>"> |
||
259 | <?php _e( 'Width', 'jetpack' ); ?> |
||
260 | <input type="number" class="smalltext" min="<?php echo esc_attr( $this->min_width ); ?>" max="<?php echo esc_attr( $this->max_width ); ?>" maxlength="3" name="<?php echo $this->get_field_name( 'width' ); ?>" id="<?php echo $this->get_field_id( 'width' ); ?>" value="<?php echo esc_attr( $instance['width'] ); ?>" style="text-align: center;" />px |
||
261 | </label> |
||
262 | </p> |
||
263 | |||
264 | <p> |
||
265 | <label for="<?php echo $this->get_field_id( 'layout' ); ?>"> |
||
266 | <?php _e( 'Layout', 'jetpack' ); ?> |
||
267 | <select name="<?php echo $this->get_field_name( 'layout' ); ?>" id="<?php echo $this->get_field_id( 'layout' ); ?>"> |
||
268 | <option value="landscape" <?php selected( $instance['layout'], 'landscape' ); ?>><?php _e( 'Landscape', 'jetpack' ); ?></option> |
||
269 | <option value="portrait" <?php selected( $instance['layout'], 'portrait' ); ?>><?php _e( 'Portrait', 'jetpack' ); ?></option> |
||
270 | </select> |
||
271 | </label> |
||
272 | </p> |
||
273 | |||
274 | <p> |
||
275 | <label for="<?php echo $this->get_field_id( 'theme' ); ?>"> |
||
276 | <?php _e( 'Theme', 'jetpack' ); ?> |
||
277 | <select name="<?php echo $this->get_field_name( 'theme' ); ?>" id="<?php echo $this->get_field_id( 'theme' ); ?>"> |
||
278 | <option value="light" <?php selected( $instance['theme'], 'light' ); ?>><?php _e( 'Light', 'jetpack' ); ?></option> |
||
279 | <option value="dark" <?php selected( $instance['theme'], 'dark' ); ?>><?php _e( 'Dark', 'jetpack' ); ?></option> |
||
280 | </select> |
||
281 | </label> |
||
282 | </p> |
||
283 | |||
284 | <p> |
||
285 | <label for="<?php echo $this->get_field_id( 'show_coverphoto' ); ?>"> |
||
286 | <input type="checkbox" name="<?php echo $this->get_field_name( 'show_coverphoto' ); ?>" id="<?php echo $this->get_field_id( 'show_coverphoto' ); ?>" <?php checked( $instance['show_coverphoto'] ); ?> class="googleplus-badge-only-person googleplus-badge-only-page" /> |
||
287 | <?php _e( 'Show Cover Photo', 'jetpack' ); ?> |
||
288 | </label> |
||
289 | </p> |
||
290 | |||
291 | <p> |
||
292 | <label for="<?php echo $this->get_field_id( 'show_photo' ); ?>"> |
||
293 | <input type="checkbox" name="<?php echo $this->get_field_name( 'show_photo' ); ?>" id="<?php echo $this->get_field_id( 'show_photo' ); ?>" <?php checked( $instance['show_photo'] ); ?> class="googleplus-badge-only-community" /> |
||
294 | <?php _e( 'Show Photo', 'jetpack' ); ?> |
||
295 | </label> |
||
296 | </p> |
||
297 | |||
298 | <p> |
||
299 | <label for="<?php echo $this->get_field_id( 'show_owners' ); ?>"> |
||
300 | <input type="checkbox" name="<?php echo $this->get_field_name( 'show_owners' ); ?>" id="<?php echo $this->get_field_id( 'show_owners' ); ?>" <?php checked( $instance['show_owners'] ); ?> class="googleplus-badge-only-community" /> |
||
301 | <?php _e( 'Show Owners', 'jetpack' ); ?> |
||
302 | </label> |
||
303 | </p> |
||
304 | |||
305 | <p> |
||
306 | <label for="<?php echo $this->get_field_id( 'show_tagline' ); ?>"> |
||
307 | <input type="checkbox" name="<?php echo $this->get_field_name( 'show_tagline' ); ?>" id="<?php echo $this->get_field_id( 'show_tagline' ); ?>" <?php checked( $instance['show_tagline'] ); ?> /> |
||
308 | <?php _e( 'Show Tag Line', 'jetpack' ); ?> |
||
309 | </label> |
||
310 | </p> |
||
311 | |||
312 | <?php |
||
313 | } |
||
314 | |||
331 |