Conditions | 3 |
Paths | 3 |
Total Lines | 63 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
181 | public function form( $instance ) { |
||
182 | // Defaults |
||
183 | $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'img_url' => '', 'alt_text' => '', 'img_title' => '', 'caption' => '', 'align' => 'none', 'img_width' => '', 'img_height' => '', 'link' => '', 'link_target_blank' => false ) ); |
||
184 | |||
185 | $title = esc_attr( $instance['title'] ); |
||
186 | $img_url = esc_url( $instance['img_url'], null, 'display' ); |
||
187 | $alt_text = esc_attr( $instance['alt_text'] ); |
||
188 | $img_title = esc_attr( $instance['img_title'] ); |
||
189 | $caption = esc_textarea( $instance['caption'] ); |
||
190 | $align = esc_attr( $instance['align'] ); |
||
191 | $img_width = esc_attr( $instance['img_width'] ); |
||
192 | $img_height = esc_attr( $instance['img_height'] ); |
||
193 | $link_target_blank = checked( $instance['link_target_blank'], true, false ); |
||
194 | |||
195 | $link = esc_url( $instance['link'], null, 'display' ); |
||
196 | |||
197 | echo '<p><label for="' . $this->get_field_id( 'title' ) . '">' . esc_html__( 'Widget title:', 'jetpack' ) . ' |
||
198 | <input class="widefat" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . $title . '" /> |
||
199 | </label></p> |
||
200 | <p><label for="' . $this->get_field_id( 'img_url' ) . '">' . esc_html__( 'Image URL:', 'jetpack' ) . ' |
||
201 | <input class="widefat" id="' . $this->get_field_id( 'img_url' ) . '" name="' . $this->get_field_name( 'img_url' ) . '" type="text" value="' . $img_url . '" /> |
||
202 | </label></p> |
||
203 | <p><label for="' . $this->get_field_id( 'alt_text' ) . '">' . esc_html__( 'Alternate text:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-alt-text" target="_blank">( ? )</a> |
||
204 | <input class="widefat" id="' . $this->get_field_id( 'alt_text' ) . '" name="' . $this->get_field_name( 'alt_text' ) . '" type="text" value="' . $alt_text . '" /> |
||
205 | </label></p> |
||
206 | <p><label for="' . $this->get_field_id( 'img_title' ) . '">' . esc_html__( 'Image title:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-title" target="_blank">( ? )</a> |
||
207 | <input class="widefat" id="' . $this->get_field_id( 'img_title' ) . '" name="' . $this->get_field_name( 'img_title' ) . '" type="text" value="' . $img_title . '" /> |
||
208 | </label></p> |
||
209 | <p><label for="' . $this->get_field_id( 'caption' ) . '">' . esc_html__( 'Caption:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-caption" target="_blank">( ? )</a> |
||
210 | <textarea class="widefat" id="' . $this->get_field_id( 'caption' ) . '" name="' . $this->get_field_name( 'caption' ) . '" rows="2" cols="20">' . $caption . '</textarea> |
||
211 | </label></p>'; |
||
212 | |||
213 | $alignments = array( |
||
214 | 'none' => __( 'None', 'jetpack' ), |
||
215 | 'left' => __( 'Left', 'jetpack' ), |
||
216 | 'center' => __( 'Center', 'jetpack' ), |
||
217 | 'right' => __( 'Right', 'jetpack' ), |
||
218 | ); |
||
219 | echo '<p><label for="' . $this->get_field_id( 'align' ) . '">' . esc_html__( 'Image Alignment:', 'jetpack' ) . ' |
||
220 | <select id="' . $this->get_field_id( 'align' ) . '" name="' . $this->get_field_name( 'align' ) . '">'; |
||
221 | foreach ( $alignments as $alignment => $alignment_name ) { |
||
222 | echo '<option value="' . esc_attr( $alignment ) . '" '; |
||
223 | if ( $alignment == $align ) |
||
224 | echo 'selected="selected" '; |
||
225 | echo '>' . esc_html($alignment_name) . "</option>\n"; |
||
226 | } |
||
227 | echo '</select></label></p>'; |
||
228 | |||
229 | echo '<p><label for="' . $this->get_field_id( 'img_width' ) . '">' . esc_html__( 'Width:', 'jetpack' ) . ' |
||
230 | <input size="3" id="' . $this->get_field_id( 'img_width' ) . '" name="' . $this->get_field_name( 'img_width' ) . '" type="text" value="' . $img_width . '" /> |
||
231 | </label> |
||
232 | <label for="' . $this->get_field_id( 'img_height' ) . '">' . esc_html__( 'Height:', 'jetpack' ) . ' |
||
233 | <input size="3" id="' . $this->get_field_id( 'img_height' ) . '" name="' . $this->get_field_name( 'img_height' ) . '" type="text" value="' . $img_height . '" /> |
||
234 | </label><br /> |
||
235 | <small>' . esc_html__( "If empty, we will attempt to determine the image size.", 'jetpack' ) . '</small></p> |
||
236 | <p><label for="' . $this->get_field_id( 'link' ) . '">' . esc_html__( 'Link URL (when the image is clicked):', 'jetpack' ) . ' |
||
237 | <input class="widefat" id="' . $this->get_field_id( 'link' ) . '" name="' . $this->get_field_name( 'link' ) . '" type="text" value="' . $link . '" /> |
||
238 | </label> |
||
239 | <label for="' . $this->get_field_id( 'link_target_blank' ) . '"> |
||
240 | <input type="checkbox" name="' . $this->get_field_name( 'link_target_blank' ) . '" id="' . $this->get_field_id( 'link_target_blank' ) . '" value="1"' . $link_target_blank . '/> |
||
241 | ' . esc_html__( 'Open link in a new window/tab', 'jetpack' ) . ' |
||
242 | </label></p>'; |
||
243 | } |
||
244 | } // Class Jetpack_Image_Widget |
||
245 |