Conditions | 10 |
Paths | 24 |
Total Lines | 45 |
Code Lines | 30 |
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 | // We want to use the HTTPS version so the URLs in the API response are also HTTPS and we avoid mixed-content warnings. |
||
75 | $rss_url = preg_replace( '!^http://api.flickr.com/!i', 'https://api.flickr.com/', $rss_url ); |
||
76 | |||
77 | $rss = fetch_feed( $rss_url ); |
||
78 | |||
79 | $photos = ''; |
||
80 | if ( ! is_wp_error( $rss ) ) { |
||
81 | foreach ( $rss->get_items( 0, $instance['items'] ) as $photo ) { |
||
82 | if ( $enclosure = $photo->get_enclosure() ) { |
||
83 | $src = str_replace( '_s.jpg', $image_size_string, $enclosure->get_thumbnail() ); |
||
84 | } else { |
||
85 | $src = preg_match( '/src="(.*?)"/i', $photo->get_description(), $p ); |
||
|
|||
86 | $src = str_replace( '_m.jpg', $image_size_string, $p[1] ); |
||
87 | } |
||
88 | |||
89 | $photos .= '<a href="' . esc_url( $photo->get_permalink(), array( 'http', 'https' ) ) . '">'; |
||
90 | $photos .= '<img src="' . esc_url( $src, array( 'http', 'https' ) ) . '" '; |
||
91 | $photos .= 'alt="' . esc_attr( $photo->get_title() ) . '" '; |
||
92 | $photos .= 'border="0" '; |
||
93 | $photos .= 'title="' . esc_attr( $photo->get_title() ) . '" '; |
||
94 | $photos .= ' /></a><br /><br />'; |
||
95 | } |
||
96 | if ( ! empty( $photos ) && class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) { |
||
97 | $photos = Jetpack_Photon::filter_the_content( $photos ); |
||
98 | } |
||
99 | |||
100 | $flickr_home = $rss->get_link(); |
||
101 | } |
||
102 | |||
103 | echo $args['before_widget']; |
||
104 | echo $args['before_title'] . esc_html( $instance['title'] ) . $args['after_title']; |
||
105 | require( dirname( __FILE__ ) . '/flickr/widget.php' ); |
||
106 | echo $args['after_widget']; |
||
107 | /** This action is already documented in modules/widgets/gravatar-profile.php */ |
||
108 | do_action( 'jetpack_stats_extra', 'widget_view', 'flickr' ); |
||
109 | } |
||
110 | |||
167 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.