Conditions | 3 |
Paths | 3 |
Total Lines | 120 |
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 |
||
18 | function form( $instance ) { |
||
|
|||
19 | $instance = wp_parse_args( $instance, array( |
||
20 | 'title' => __( 'Testimonials', 'ivycat-ajax-testimonials' ), |
||
21 | 'testimonial_group' => 0, |
||
22 | 'testimonial_quantity' => 3, |
||
23 | 'testimonial_num_words' => 0, |
||
24 | 'testimonial_read_more' => 0, |
||
25 | 'testimonial_ajax_on' => false, |
||
26 | 'testimonial_display' => 'single', |
||
27 | 'testimonial_link_testimonials' => false, |
||
28 | 'testimonial_show_all_title' => __( 'See All Testimonials', 'ivycat-ajax-testimonials' ), |
||
29 | 'testimonial_show_all' => get_bloginfo( 'url' ), |
||
30 | 'template' => '', |
||
31 | 'testimonial_slide_speed' => 8000, |
||
32 | 'testimonial_fadein' => 1000, |
||
33 | 'testimonial_fadeout' => 1000, |
||
34 | ) ); ?> |
||
35 | |||
36 | <p> |
||
37 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'ivycat-ajax-testimonials' ); ?></label> |
||
38 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" |
||
39 | id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" |
||
40 | value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat"> |
||
41 | </p> |
||
42 | <p> |
||
43 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_group' ) ); ?>"><?php _e( 'Display Testimonial Group:', 'ivycat-ajax-testimonials' ); ?></label> |
||
44 | <select name="<?php echo esc_attr( $this->get_field_name( 'testimonial_group' ) ); ?>" |
||
45 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_group' ) ); ?>" class="widefat"> |
||
46 | <option><?php _e( 'All Groups', 'ivycat-ajax-testimonials' ); ?></option><?php |
||
47 | $cats = get_terms( 'testimonial-group', array( 'hide_empty' => 0 ) ); |
||
48 | foreach ( ( object ) $cats as $cat ) : |
||
49 | if ( array_key_exists( 'testimonial_group', $instance ) ) { |
||
50 | printf( '<option value="%s"%s">%s</option>', |
||
51 | $cat->slug, |
||
52 | selected( $instance['testimonial_group'], $cat->slug, false ), |
||
53 | $cat->name |
||
54 | ); |
||
55 | } |
||
56 | endforeach; ?> |
||
57 | </select> |
||
58 | </p> |
||
59 | <p> |
||
60 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_quantity' ) ); ?>"><?php _e( 'How many testimonials in rotation?', 'ivycat-ajax-testimonials' ); ?></label> |
||
61 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_quantity' ) ); ?>" |
||
62 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_quantity' ) ); ?>" class="widefat" |
||
63 | value="<?php echo absint( $instance['testimonial_quantity'] ); ?>"/> |
||
64 | </p> |
||
65 | <p> |
||
66 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_num_words' ) ); ?>"><?php _e( 'Number of Words (0 for all)', 'ivycat-ajax-testimonials' ); ?></label> |
||
67 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_num_words' ) ); ?>" |
||
68 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_num_words' ) ); ?>" class="widefat" |
||
69 | value="<?php echo absint( $instance['testimonial_num_words'] ); ?>"/> |
||
70 | </p> |
||
71 | <p> |
||
72 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_read_more' ) ); ?>"><?php _e( 'Read More Text', 'ivycat-ajax-testimonials' ); ?></label> |
||
73 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_read_more' ) ); ?>" |
||
74 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_read_more' ) ); ?>" class="widefat" |
||
75 | value="<?php echo esc_attr( $instance['testimonial_read_more'] ); ?>"/> |
||
76 | </p> |
||
77 | <p> |
||
78 | <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_ajax_on' ) ); ?>" |
||
79 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_ajax_on' ) ); ?>" class="checkbox" |
||
80 | value="no"<?php checked( $instance['testimonial_ajax_on'] ); ?>/> |
||
81 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_ajax_on' ) ); ?>"><?php _e( 'Disable AJAX', 'ivycat-ajax-testimonials' ); ?></label> |
||
82 | </p> |
||
83 | <p> |
||
84 | <input type="checkbox" |
||
85 | name="<?php echo esc_attr( $this->get_field_name( 'testimonial_link_testimonials' ) ); ?>" |
||
86 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_link_testimonials' ) ); ?>" |
||
87 | class="checkbox" |
||
88 | value="yes"<?php checked( $instance['testimonial_link_testimonials'] ); ?>/> |
||
89 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_link_testimonials' ) ); ?>"><?php _e( 'Link Individual Testimonials', 'ivycat-ajax-testimonials' ); ?></label> |
||
90 | </p> |
||
91 | <p> |
||
92 | <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_display' ) ); ?>" |
||
93 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_display' ) ); ?>" class="checkbox" |
||
94 | value="single"<?php checked( $instance['testimonial_display'], 'list' ); ?>/> |
||
95 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_display' ) ); ?>"><?php _e( 'List Mode', 'ivycat-ajax-testimonials' ); ?></label> |
||
96 | </p> |
||
97 | <p> |
||
98 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_show_all_title' ) ); ?>"><?php _e( 'Title for Link to all Testimonials', 'ivycat-ajax-testimonials' ); ?></label> |
||
99 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_show_all_title' ) ); ?>" |
||
100 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_show_all_title' ) ); ?>" class="widefat" |
||
101 | value="<?php echo esc_attr( $instance['testimonial_show_all_title'] ); ?>"/> |
||
102 | </p> |
||
103 | <p> |
||
104 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_show_all' ) ); ?>"><?php _e( 'Link to all Testimonials', 'ivycat-ajax-testimonials' ); ?></label> |
||
105 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_show_all' ) ); ?>" |
||
106 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_show_all' ) ); ?>" class="widefat" |
||
107 | value="<?php echo esc_url( $instance['testimonial_show_all'] ); ?>"/> |
||
108 | </p> |
||
109 | <p> |
||
110 | <label for="<?php echo esc_attr( $this->get_field_id( 'template' ) ); ?>"><?php _e( 'Custom Template (enable List Mode)', 'ivycat-ajax-testimonials' ); ?></label> |
||
111 | <input type="text" placeholder="Place file in theme folder" |
||
112 | name="<?php echo esc_attr( $this->get_field_name( 'template' ) ); ?>" |
||
113 | id="<?php echo esc_attr( $this->get_field_id( 'template' ) ); ?>" class="widefat" |
||
114 | value="<?php echo esc_attr( $instance['template'] ); ?>"/> |
||
115 | </p> |
||
116 | <h3>Testimonial Rotation Settings</h3> |
||
117 | <p> |
||
118 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_slide_speed' ) ); ?>"><?php _e( 'Testimonial Rotation (miliseconds)', 'ivycat-ajax-testimonials' ); ?></label> |
||
119 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_slide_speed' ) ); ?>" |
||
120 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_slide_speed' ) ); ?>" class="widefat" |
||
121 | value="<?php echo absint( $instance['testimonial_slide_speed'] ); ?>"/> |
||
122 | </p> |
||
123 | <p> |
||
124 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_fadein' ) ); ?>"><?php _e( 'Testimonial Fade In (miliseconds)', 'ivycat-ajax-testimonials' ); ?></label> |
||
125 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_fadein' ) ); ?>" |
||
126 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_fadein' ) ); ?>" class="widefat" |
||
127 | value="<?php echo absint( $instance['testimonial_fadein'] ); ?>"/> |
||
128 | </p> |
||
129 | <p> |
||
130 | <label for="<?php echo esc_attr( $this->get_field_id( 'testimonial_fadeout' ) ); ?>"><?php _e( 'Testimonial Fade Out (miliseconds)', 'ivycat-ajax-testimonials' ); ?></label> |
||
131 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'testimonial_fadeout' ) ); ?>" |
||
132 | id="<?php echo esc_attr( $this->get_field_id( 'testimonial_fadeout' ) ); ?>" class="widefat" |
||
133 | value="<?php echo absint( $instance['testimonial_fadeout'] ); ?>"/> |
||
134 | </p> |
||
135 | <?php |
||
136 | do_action( 'ic_testimonials_widget_form', $instance ); |
||
137 | } |
||
138 | |||
187 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.