Conditions | 4 |
Paths | 8 |
Total Lines | 93 |
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 |
||
178 | function get_options( $wp_customize ) { |
||
179 | $transport = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh'; |
||
180 | |||
181 | // Get the correct translated string for preview in WP 4.7 and later. |
||
182 | $switched_locale = function_exists( 'switch_to_locale' ) |
||
183 | ? switch_to_locale( get_user_locale() ) |
||
184 | : false; |
||
185 | $headline = __( 'Related', 'jetpack' ); |
||
186 | if ( $switched_locale ) { |
||
187 | restore_previous_locale(); |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * The filter allows you to change the options used to display Related Posts in the Customizer. |
||
192 | * |
||
193 | * @module related-posts |
||
194 | * |
||
195 | * @since 4.4.0 |
||
196 | * |
||
197 | * @param array $options Array of options used to display Related Posts in the Customizer. |
||
198 | */ |
||
199 | return apply_filters( |
||
200 | 'jetpack_related_posts_customize_options', array( |
||
201 | 'enabled' => array( |
||
202 | 'control_type' => 'hidden', |
||
203 | 'default' => 1, |
||
204 | 'setting_type' => 'option', |
||
205 | 'transport' => $transport, |
||
206 | ), |
||
207 | 'show_headline' => array( |
||
208 | 'label' => esc_html__( 'Show a headline', 'jetpack' ), |
||
209 | 'description' => esc_html__( 'This helps to clearly separate the related posts from post content.', 'jetpack' ), |
||
210 | 'control_type' => 'checkbox', |
||
211 | 'default' => 1, |
||
212 | 'setting_type' => 'option', |
||
213 | 'transport' => $transport, |
||
214 | ), |
||
215 | 'headline' => array( |
||
216 | 'label' => '', |
||
217 | 'description' => esc_html__( 'Enter text to use as headline.', 'jetpack' ), |
||
218 | 'control_type' => 'text', |
||
219 | 'default' => esc_html( $headline ), |
||
220 | 'setting_type' => 'option', |
||
221 | 'transport' => $transport, |
||
222 | ), |
||
223 | 'show_thumbnails' => array( |
||
224 | 'label' => esc_html__( 'Show thumbnails', 'jetpack' ), |
||
225 | 'description' => esc_html__( 'Show a thumbnail image where available.', 'jetpack' ), |
||
226 | 'control_type' => 'checkbox', |
||
227 | 'default' => 1, |
||
228 | 'setting_type' => 'option', |
||
229 | 'transport' => $transport, |
||
230 | ), |
||
231 | 'show_date' => array( |
||
232 | 'label' => esc_html__( 'Show date', 'jetpack' ), |
||
233 | 'description' => esc_html__( 'Display date when entry was published.', 'jetpack' ), |
||
234 | 'control_type' => 'checkbox', |
||
235 | 'default' => 1, |
||
236 | 'setting_type' => 'option', |
||
237 | 'transport' => $transport, |
||
238 | ), |
||
239 | 'show_context' => array( |
||
240 | 'label' => esc_html__( 'Show context', 'jetpack' ), |
||
241 | 'description' => esc_html__( "Display entry's category or tag.", 'jetpack' ), |
||
242 | 'control_type' => 'checkbox', |
||
243 | 'default' => 1, |
||
244 | 'setting_type' => 'option', |
||
245 | 'transport' => $transport, |
||
246 | ), |
||
247 | 'layout' => array( |
||
248 | 'label' => esc_html__( 'Layout', 'jetpack' ), |
||
249 | 'description' => esc_html__( 'Arrange entries in different layouts.', 'jetpack' ), |
||
250 | 'control_type' => 'select', |
||
251 | 'choices' => array( |
||
252 | 'grid' => esc_html__( 'Grid', 'jetpack' ), |
||
253 | 'list' => esc_html__( 'List', 'jetpack' ), |
||
254 | ), |
||
255 | 'default' => 'grid', |
||
256 | 'setting_type' => 'option', |
||
257 | 'transport' => $transport, |
||
258 | ), |
||
259 | 'msg_go_to_single' => array( |
||
260 | 'description' => esc_html__( 'Please visit a single post view to reveal the customization options.', 'jetpack' ), |
||
261 | 'control_type' => 'message', |
||
262 | 'active_callback' => __CLASS__ . '::is_not_single', |
||
263 | ), |
||
264 | 'msg_example' => array( |
||
265 | 'description' => esc_html__( 'Please note that the related posts displayed now are only for previewing purposes.', 'jetpack' ), |
||
266 | 'control_type' => 'message', |
||
267 | ), |
||
268 | ) |
||
269 | ); |
||
270 | } |
||
271 | |||
310 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.