| Conditions | 18 |
| Paths | 180 |
| Total Lines | 92 |
| Code Lines | 53 |
| 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 | if ( ! empty( $instance['flickr_rss_url'] ) ) { |
||
| 71 | |||
| 72 | /* |
||
| 73 | * Parse the URL, and rebuild a URL that's sure to display images. |
||
| 74 | * Some Flickr Feeds do not display images by default. |
||
| 75 | */ |
||
| 76 | $flickr_parameters = parse_url( htmlspecialchars_decode( $instance['flickr_rss_url'] ) ); |
||
| 77 | |||
| 78 | // Is it a Flickr Feed. |
||
| 79 | if ( |
||
| 80 | ! empty( $flickr_parameters['host'] ) |
||
| 81 | && ! empty( $flickr_parameters['query'] ) |
||
| 82 | && false !== strpos( $flickr_parameters['host'], 'flickr' ) |
||
| 83 | ) { |
||
| 84 | parse_str( $flickr_parameters['query'], $vars ); |
||
| 85 | |||
| 86 | // Do we have an ID in the feed? Let's continue. |
||
| 87 | if ( isset( $vars['id'] ) ) { |
||
| 88 | |||
| 89 | // Flickr Feeds can be used for groups or for individuals. |
||
| 90 | if ( |
||
| 91 | ! empty( $flickr_parameters['path'] ) |
||
| 92 | && false !== strpos( $flickr_parameters['path'], 'groups' ) |
||
| 93 | ) { |
||
| 94 | $feed_url = 'https://api.flickr.com/services/feeds/groups_pool.gne'; |
||
| 95 | } else { |
||
| 96 | $feed_url = 'https://api.flickr.com/services/feeds/photos_public.gne'; |
||
| 97 | } |
||
| 98 | |||
| 99 | // Build our new RSS feed. |
||
| 100 | $rss_url = sprintf( |
||
| 101 | '%1$s?id=%2$s&format=rss_200_enc', |
||
| 102 | esc_url( $feed_url ), |
||
| 103 | esc_attr( $vars['id'] ) |
||
| 104 | ); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } // End if(). |
||
| 108 | |||
| 109 | // Still no RSS feed URL? Get a default feed from Flickr to grab interesting photos. |
||
| 110 | if ( empty( $rss_url ) ) { |
||
| 111 | $rss_url = 'https://api.flickr.com/services/feeds/photos_interesting.gne?format=rss_200'; |
||
| 112 | } |
||
| 113 | |||
| 114 | $rss = fetch_feed( $rss_url ); |
||
| 115 | |||
| 116 | $photos = ''; |
||
| 117 | if ( ! is_wp_error( $rss ) ) { |
||
| 118 | foreach ( $rss->get_items( 0, $instance['items'] ) as $photo ) { |
||
| 119 | if ( $enclosure = $photo->get_enclosure() ) { |
||
| 120 | $src = str_replace( '_s.jpg', $image_size_string, $enclosure->get_thumbnail() ); |
||
| 121 | } else { |
||
| 122 | $src = preg_match( '/src="(.*?)"/i', $photo->get_description(), $p ); |
||
|
|
|||
| 123 | $src = str_replace( '_m.jpg', $image_size_string, $p[1] ); |
||
| 124 | } |
||
| 125 | |||
| 126 | $photos .= '<a href="' . esc_url( $photo->get_permalink(), array( 'http', 'https' ) ) . '">'; |
||
| 127 | $photos .= '<img src="' . esc_url( $src, array( 'http', 'https' ) ) . '" '; |
||
| 128 | $photos .= 'alt="' . esc_attr( $photo->get_title() ) . '" '; |
||
| 129 | $photos .= 'border="0" '; |
||
| 130 | $photos .= 'title="' . esc_attr( $photo->get_title() ) . '" '; |
||
| 131 | $photos .= ' /></a><br /><br />'; |
||
| 132 | } |
||
| 133 | if ( ! empty( $photos ) && class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) { |
||
| 134 | $photos = Jetpack_Photon::filter_the_content( $photos ); |
||
| 135 | } |
||
| 136 | |||
| 137 | $flickr_home = $rss->get_link(); |
||
| 138 | } |
||
| 139 | |||
| 140 | echo $args['before_widget']; |
||
| 141 | if ( empty( $photos ) ) { |
||
| 142 | if ( current_user_can( 'edit_theme_options' ) ) { |
||
| 143 | printf( |
||
| 144 | '<p>%1$s<br />%2$s</p>', |
||
| 145 | esc_html__( 'There are no photos to display. Make sure your Flickr feed URL is correct, and that your pictures are publicly accessible.', 'jetpack' ), |
||
| 146 | esc_html__( '(Only admins can see this message)', 'jetpack' ) |
||
| 147 | ); |
||
| 148 | } |
||
| 149 | } else { |
||
| 150 | echo $args['before_title'] . esc_html( $instance['title'] ) . $args['after_title']; |
||
| 151 | require( dirname( __FILE__ ) . '/flickr/widget.php' ); |
||
| 152 | } |
||
| 153 | echo $args['after_widget']; |
||
| 154 | /** This action is already documented in modules/widgets/gravatar-profile.php */ |
||
| 155 | do_action( 'jetpack_stats_extra', 'widget_view', 'flickr' ); |
||
| 156 | } |
||
| 157 | |||
| 214 |
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.