| Conditions | 12 |
| Paths | 36 |
| Total Lines | 81 |
| Code Lines | 39 |
| Lines | 3 |
| Ratio | 3.7 % |
| 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 |
||
| 114 | public function widget( $args, $instance ) { |
||
| 115 | $instance = wp_parse_args( (array) $instance, $this->defaults ); |
||
| 116 | /** This filter is documented in core/src/wp-includes/default-widgets.php */ |
||
| 117 | $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
||
| 118 | if ( ! $this->check_genericons() ) { |
||
| 119 | wp_enqueue_style( 'genericons' ); |
||
| 120 | } |
||
| 121 | $index = 10; |
||
| 122 | $html = array(); |
||
| 123 | $alt_text = esc_attr__( 'View %1$s’s profile on %2$s', 'jetpack' ); |
||
| 124 | foreach ( $this->services as $service => $data ) { |
||
| 125 | list( $service_name, $url ) = $data; |
||
| 126 | if ( ! isset( $instance[ $service . '_username' ] ) ) { |
||
| 127 | continue; |
||
| 128 | } |
||
| 129 | $username = $link_username = $instance[ $service . '_username' ]; |
||
| 130 | if ( empty( $username ) ) { |
||
| 131 | continue; |
||
| 132 | } |
||
| 133 | $index += 10; |
||
| 134 | if ( |
||
| 135 | 'googleplus' === $service |
||
| 136 | && ! is_numeric( $username ) |
||
| 137 | && substr( $username, 0, 1 ) !== '+' |
||
| 138 | ) { |
||
| 139 | $link_username = '+' . $username; |
||
| 140 | } |
||
| 141 | if ( 'youtube' === $service && 'UC' === substr( $username, 0, 2 ) ) { |
||
| 142 | $link_username = 'channel/' . $username; |
||
| 143 | } else if ( 'youtube' === $service ) { |
||
| 144 | $link_username = 'user/' . $username; |
||
| 145 | } |
||
| 146 | /** |
||
| 147 | * Fires for each profile link in the social icons widget. Can be used |
||
| 148 | * to change the links for certain social networks if needed. |
||
| 149 | * |
||
| 150 | * @module widgets |
||
| 151 | * |
||
| 152 | * @since 3.8.0 |
||
| 153 | * |
||
| 154 | * @param string $url the currently processed URL |
||
| 155 | * @param string $service the lowercase service slug, e.g. 'facebook', 'youtube', etc. |
||
| 156 | */ |
||
| 157 | $link = apply_filters( 'jetpack_social_media_icons_widget_profile_link', esc_url( sprintf( $url, $link_username ) ), $service ); |
||
| 158 | $html[ $index ] = |
||
| 159 | '<a title="' . sprintf( $alt_text, esc_attr( $username ), $service_name ) |
||
| 160 | . '" href="' . $link |
||
| 161 | . '" class="genericon genericon-' . $service . '" target="_blank"><span class="screen-reader-text">' |
||
| 162 | . sprintf( $alt_text, esc_html( $username ), $service_name ) |
||
| 163 | . '</span></a>'; |
||
| 164 | } |
||
| 165 | /** |
||
| 166 | * Fires at the end of the list of Social Media accounts. |
||
| 167 | * Can be used to add a new Social Media Site to the Social Media Icons Widget. |
||
| 168 | * The filter function passed the array of HTML entries that will be sorted |
||
| 169 | * by key, each wrapped in a list item element and output as an unsorted list. |
||
| 170 | * |
||
| 171 | * @module widgets |
||
| 172 | * |
||
| 173 | * @since 3.8.0 |
||
| 174 | * |
||
| 175 | * @param array $html Associative array of HTML snippets per each icon. |
||
| 176 | */ |
||
| 177 | $html = apply_filters( 'jetpack_social_media_icons_widget_array', $html ); |
||
| 178 | ksort( $html ); |
||
| 179 | $html = '<ul><li>' . join( '</li><li>', $html ) . '</li></ul>'; |
||
| 180 | View Code Duplication | if ( ! empty( $instance['title'] ) ) { |
|
| 181 | $html = $args['before_title'] . esc_html( $instance['title'] ) . $args['after_title'] . $html; |
||
| 182 | } |
||
| 183 | $html = $args['before_widget'] . $html . $args['after_widget']; |
||
| 184 | /** |
||
| 185 | * Filters the Social Media Icons widget output. |
||
| 186 | * |
||
| 187 | * @module widgets |
||
| 188 | * |
||
| 189 | * @since 3.6.0 |
||
| 190 | * |
||
| 191 | * @param string $html Social Media Icons widget html output. |
||
| 192 | */ |
||
| 193 | echo apply_filters( 'jetpack_social_media_icons_widget_output', $html ); |
||
| 194 | } |
||
| 195 | |||
| 296 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.