| Conditions | 16 |
| Paths | 20 |
| Total Lines | 50 |
| Code Lines | 30 |
| Lines | 11 |
| Ratio | 22 % |
| 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 |
||
| 80 | function jetpack_featured_images_fallback_get_image_src( $post_id, $post_thumbnail_id, $size ) { |
||
| 81 | $image_src = wp_get_attachment_image_src( $post_thumbnail_id, $size ); |
||
| 82 | $image_src = ( ! empty( $image_src[0] ) ) ? $image_src[0] : null; |
||
| 83 | $opts = jetpack_featured_images_get_settings(); |
||
| 84 | |||
| 85 | if ( ! empty( $image_src ) || (bool) 1 !== (bool) $opts['fallback-option'] ) { |
||
| 86 | return esc_url( $image_src ); |
||
| 87 | } |
||
| 88 | |||
| 89 | View Code Duplication | if ( jetpack_featured_images_should_load() ) { |
|
| 90 | if ( ( true === $opts['archive'] && ( is_home() || is_archive() || is_search() ) && ! $opts['archive-option'] ) |
||
| 91 | || ( true === $opts['post'] && is_single() && ! $opts['post-option'] ) ) { |
||
| 92 | return esc_url( $image_src ); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | if ( class_exists( 'Jetpack_PostImages' ) ) { |
||
| 97 | global $_wp_additional_image_sizes; |
||
| 98 | |||
| 99 | $args = array( |
||
| 100 | 'from_thumbnail' => false, |
||
| 101 | 'from_slideshow' => true, |
||
| 102 | 'from_gallery' => true, |
||
| 103 | 'from_attachment' => false, |
||
| 104 | ); |
||
| 105 | |||
| 106 | $image = Jetpack_PostImages::get_image( $post_id, $args ); |
||
| 107 | |||
| 108 | if ( ! empty( $image ) ) { |
||
| 109 | $image['width'] = ''; |
||
| 110 | $image['height'] = ''; |
||
| 111 | $image['crop'] = ''; |
||
| 112 | |||
| 113 | View Code Duplication | if ( array_key_exists( $size, $_wp_additional_image_sizes ) ) { |
|
| 114 | $image['width'] = $_wp_additional_image_sizes[ $size ]['width']; |
||
| 115 | $image['height'] = $_wp_additional_image_sizes[ $size ]['height']; |
||
| 116 | $image['crop'] = $_wp_additional_image_sizes[ $size ]['crop']; |
||
| 117 | } |
||
| 118 | |||
| 119 | $image_src = Jetpack_PostImages::fit_image_url( $image['src'], $image['width'], $image['height'] ); |
||
| 120 | |||
| 121 | // Use the theme's crop setting rather than forcing to true |
||
| 122 | $image_src = add_query_arg( 'crop', $image['crop'], $image_src ); |
||
| 123 | |||
| 124 | return esc_url( $image_src ); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | return esc_url( $image_src ); |
||
| 129 | } |
||
| 130 | |||
| 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.