| Conditions | 13 |
| Paths | 72 |
| Total Lines | 71 |
| Code Lines | 42 |
| 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 |
||
| 65 | public function widget( $args, $instance ) { |
||
| 66 | $instance = wp_parse_args( $instance, $this->defaults() ); |
||
| 67 | |||
| 68 | $image_size_string = 'small' == $instance['flickr_image_size'] ? '_m.jpg' : '_t.jpg'; |
||
| 69 | |||
| 70 | $rss_url = ( ! isset( $instance['flickr_rss_url'] ) || empty( $instance['flickr_rss_url'] ) ) |
||
| 71 | ? 'https://api.flickr.com/services/feeds/photos_interesting.gne?format=rss_200' |
||
| 72 | : htmlspecialchars_decode( $instance['flickr_rss_url'] ); |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Parse the URL, and rebuild a URL that's sure to display images. |
||
| 76 | * Some Flickr Feeds do not display images by default. |
||
| 77 | */ |
||
| 78 | $flickr_parameters = parse_url( $rss_url ); |
||
| 79 | parse_str( $flickr_parameters['query'], $vars ); |
||
| 80 | |||
| 81 | // Do we have an ID in the feed? Let's continue. |
||
| 82 | if ( isset( $vars['id'] ) ) { |
||
| 83 | /** |
||
| 84 | * Flickr Feeds can be used for groups or for individuals. |
||
| 85 | */ |
||
| 86 | if ( |
||
| 87 | ! empty( $flickr_parameters['path'] ) |
||
| 88 | && false !== strpos( $flickr_parameters['path'], 'groups' ) |
||
| 89 | ) { |
||
| 90 | $feed_url = 'https://api.flickr.com/services/feeds/groups_pool.gne'; |
||
| 91 | } else { |
||
| 92 | $feed_url = 'https://api.flickr.com/services/feeds/photos_public.gne'; |
||
| 93 | } |
||
| 94 | |||
| 95 | // Build our new RSS feed. |
||
| 96 | $rss_url = sprintf( |
||
| 97 | '%1$s?id=%2$s&format=rss_200_enc', |
||
| 98 | esc_url( $feed_url ), |
||
| 99 | esc_attr( $vars['id'] ) |
||
| 100 | ); |
||
| 101 | } |
||
| 102 | |||
| 103 | $rss = fetch_feed( $rss_url ); |
||
| 104 | |||
| 105 | $photos = ''; |
||
| 106 | if ( ! is_wp_error( $rss ) ) { |
||
| 107 | foreach ( $rss->get_items( 0, $instance['items'] ) as $photo ) { |
||
| 108 | if ( $enclosure = $photo->get_enclosure() ) { |
||
| 109 | $src = str_replace( '_s.jpg', $image_size_string, $enclosure->get_thumbnail() ); |
||
| 110 | } else { |
||
| 111 | $src = preg_match( '/src="(.*?)"/i', $photo->get_description(), $p ); |
||
|
|
|||
| 112 | $src = str_replace( '_m.jpg', $image_size_string, $p[1] ); |
||
| 113 | } |
||
| 114 | |||
| 115 | $photos .= '<a href="' . esc_url( $photo->get_permalink(), array( 'http', 'https' ) ) . '">'; |
||
| 116 | $photos .= '<img src="' . esc_url( $src, array( 'http', 'https' ) ) . '" '; |
||
| 117 | $photos .= 'alt="' . esc_attr( $photo->get_title() ) . '" '; |
||
| 118 | $photos .= 'border="0" '; |
||
| 119 | $photos .= 'title="' . esc_attr( $photo->get_title() ) . '" '; |
||
| 120 | $photos .= ' /></a><br /><br />'; |
||
| 121 | } |
||
| 122 | if ( ! empty( $photos ) && class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) { |
||
| 123 | $photos = Jetpack_Photon::filter_the_content( $photos ); |
||
| 124 | } |
||
| 125 | |||
| 126 | $flickr_home = $rss->get_link(); |
||
| 127 | } |
||
| 128 | |||
| 129 | echo $args['before_widget']; |
||
| 130 | echo $args['before_title'] . esc_html( $instance['title'] ) . $args['after_title']; |
||
| 131 | require( dirname( __FILE__ ) . '/flickr/widget.php' ); |
||
| 132 | echo $args['after_widget']; |
||
| 133 | /** This action is already documented in modules/widgets/gravatar-profile.php */ |
||
| 134 | do_action( 'jetpack_stats_extra', 'widget_view', 'flickr' ); |
||
| 135 | } |
||
| 136 | |||
| 193 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.