Conditions | 16 |
Paths | 10 |
Total Lines | 53 |
Code Lines | 31 |
Lines | 11 |
Ratio | 20.75 % |
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 |
||
15 | function jetpack_featured_images_fallback_get_image( $html, $post_id, $post_thumbnail_id, $size, $attr ) { |
||
16 | $opts = jetpack_featured_images_get_settings(); |
||
17 | |||
18 | if ( ! empty( $html ) || (bool) 1 !== (bool) $opts['fallback-option'] ) { |
||
19 | return trim( $html ); |
||
20 | } |
||
21 | |||
22 | View Code Duplication | if ( jetpack_featured_images_should_load() ) { |
|
23 | if ( |
||
24 | ( true === $opts['archive'] && ( is_home() || is_archive() || is_search() ) && ! $opts['archive-option'] ) |
||
25 | || ( true === $opts['post'] && is_single() && ! $opts['post-option'] ) |
||
26 | || ! $opts['fallback-option'] |
||
27 | ) { |
||
28 | return trim( $html ); |
||
29 | } |
||
30 | } |
||
31 | |||
32 | if ( class_exists( 'Jetpack_PostImages' ) ) { |
||
33 | global $_wp_additional_image_sizes; |
||
34 | |||
35 | $args = array( |
||
36 | 'from_thumbnail' => false, |
||
37 | 'from_slideshow' => true, |
||
38 | 'from_gallery' => true, |
||
39 | 'from_attachment' => false, |
||
40 | ); |
||
41 | |||
42 | $image = Jetpack_PostImages::get_image( $post_id, $args ); |
||
43 | |||
44 | if ( ! empty( $image ) ) { |
||
45 | $image['width'] = ''; |
||
46 | $image['height'] = ''; |
||
47 | $image['crop'] = ''; |
||
48 | |||
49 | View Code Duplication | if ( array_key_exists( $size, $_wp_additional_image_sizes ) ) { |
|
50 | $image['width'] = $_wp_additional_image_sizes[ $size ]['width']; |
||
51 | $image['height'] = $_wp_additional_image_sizes[ $size ]['height']; |
||
52 | $image['crop'] = $_wp_additional_image_sizes[ $size ]['crop']; |
||
53 | } |
||
54 | |||
55 | $image_src = Jetpack_PostImages::fit_image_url( $image['src'], $image['width'], $image['height'] ); |
||
56 | |||
57 | // Use the theme's crop setting rather than forcing to true |
||
58 | $image_src = add_query_arg( 'crop', $image['crop'], $image_src ); |
||
59 | |||
60 | $html = '<img src="' . esc_url( $image_src ) . '" title="' . esc_attr( strip_tags( get_the_title() ) ) . '" class="attachment-' . esc_attr( $size ) . ' wp-post-image" />'; |
||
|
|||
61 | |||
62 | return trim( $html ); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | return trim( $html ); |
||
67 | } |
||
68 | add_filter( 'post_thumbnail_html', 'jetpack_featured_images_fallback_get_image', 10, 5 ); |
||
162 |
This check looks for improperly formatted assignments.
Every assignment must have exactly one space before and one space after the equals operator.
To illustrate:
will have no issues, while
will report issues in lines 1 and 2.