Conditions | 12 |
Paths | 36 |
Total Lines | 97 |
Code Lines | 39 |
Lines | 3 |
Ratio | 3.09 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
75 | public function widget( $args, $instance ) { |
||
76 | $instance = wp_parse_args( (array) $instance, $this->defaults ); |
||
77 | /** This filter is documented in core/src/wp-includes/default-widgets.php */ |
||
78 | $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
||
79 | |||
80 | if ( ! $this->check_social_icons() ) { |
||
81 | wp_enqueue_style( 'social-logos' ); |
||
82 | } |
||
83 | |||
84 | $index = 10; |
||
85 | $html = array(); |
||
86 | |||
87 | $alt_text = esc_attr__( 'View %1$s’s profile on %2$s', 'jetpack' ); |
||
88 | |||
89 | foreach ( $this->services as $service => $data ) { |
||
90 | list( $service_name, $url ) = $data; |
||
91 | |||
92 | if ( ! isset( $instance[ $service . '_username' ] ) ) { |
||
93 | continue; |
||
94 | } |
||
95 | $username = $link_username = $instance[ $service . '_username' ]; |
||
96 | |||
97 | if ( empty( $username ) ) { |
||
98 | continue; |
||
99 | } |
||
100 | |||
101 | $index += 10; |
||
102 | |||
103 | if ( |
||
104 | $service === 'googleplus' |
||
105 | && ! is_numeric( $username ) |
||
106 | && substr( $username, 0, 1 ) !== "+" |
||
107 | ) { |
||
108 | $link_username = "+" . $username; |
||
109 | } |
||
110 | |||
111 | if ( $service === 'youtube' && substr( $username, 0, 2 ) == 'UC' ) { |
||
112 | $link_username = "channel/" . $username; |
||
113 | } else if ( $service === 'youtube' ) { |
||
114 | $link_username = "user/" . $username; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Fires for each profile link in the social icons widget. Can be used |
||
119 | * to change the links for certain social networks if needed. |
||
120 | * |
||
121 | * @module widgets |
||
122 | * |
||
123 | * @since 3.8.0 |
||
124 | * |
||
125 | * @param string $url the currently processed URL |
||
126 | * @param string $service the lowercase service slug, e.g. 'facebook', 'youtube', etc. |
||
127 | */ |
||
128 | $link = apply_filters( 'jetpack_social_media_icons_widget_profile_link', esc_url( sprintf( $url, $link_username ) ), $service ); |
||
129 | |||
130 | $html[ $index ] = |
||
131 | '<a title="' . sprintf( $alt_text, esc_attr( $username ), $service_name ) |
||
132 | . '" href="' . $link |
||
133 | . '" class="genericon genericon-' . $service . '" target="_blank"><span class="screen-reader-text">' |
||
134 | . sprintf( $alt_text, esc_html( $username ), $service_name ) |
||
135 | . '</span></a>'; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Fires at the end of the list of Social Media accounts. |
||
140 | * Can be used to add a new Social Media Site to the Social Media Icons Widget. |
||
141 | * The filter function passed the array of HTML entries that will be sorted |
||
142 | * by key, each wrapped in a list item element and output as an unsorted list. |
||
143 | * |
||
144 | * @module widgets |
||
145 | * |
||
146 | * @since 3.8.0 |
||
147 | * |
||
148 | * @param array $html Associative array of HTML snippets per each icon. |
||
149 | */ |
||
150 | $html = apply_filters( 'jetpack_social_media_icons_widget_array', $html ); |
||
151 | |||
152 | ksort( $html ); |
||
153 | $html = '<ul><li>' . join( '</li><li>', $html ) . '</li></ul>'; |
||
154 | |||
155 | View Code Duplication | if ( ! empty( $instance['title'] ) ) { |
|
156 | $html = $args['before_title'] . esc_html( $instance['title'] ) . $args['after_title'] . $html; |
||
157 | } |
||
158 | |||
159 | $html = $args['before_widget'] . $html . $args['after_widget']; |
||
160 | |||
161 | /** |
||
162 | * Filters the Social Media Icons widget output. |
||
163 | * |
||
164 | * @module widgets |
||
165 | * |
||
166 | * @since 3.6.0 |
||
167 | * |
||
168 | * @param string $html Social Media Icons widget html output. |
||
169 | */ |
||
170 | echo apply_filters( 'jetpack_social_media_icons_widget_output', $html ); |
||
171 | } |
||
172 | |||
254 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.