| Conditions | 10 |
| Paths | 4 |
| Total Lines | 42 |
| Code Lines | 21 |
| 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 |
||
| 20 | function add_retina_attributes($attr, $args, $attachment) { |
||
| 21 | global $current_foogallery; |
||
| 22 | |||
| 23 | if ( $current_foogallery && $current_foogallery->gallery_template ) { |
||
| 24 | |||
| 25 | //first check if the gallery template supports Retina thumbs |
||
| 26 | if ( $current_foogallery->retina ) { |
||
| 27 | $srcset = array(); |
||
| 28 | |||
| 29 | $original_width = intval( $args['width'] ); |
||
| 30 | $original_height = intval( $args['height'] ); |
||
| 31 | |||
| 32 | foreach ( foogallery_retina_options() as $pixel_density ) { |
||
| 33 | $pixel_density_supported = array_key_exists( $pixel_density, $current_foogallery->retina ) ? ('true' === $current_foogallery->retina[$pixel_density]) : false; |
||
| 34 | |||
| 35 | if ( $pixel_density_supported ) { |
||
| 36 | $pixel_density_int = intval( str_replace( 'x', '', $pixel_density ) ); |
||
| 37 | |||
| 38 | //apply scaling to the width and height attributes |
||
| 39 | $retina_width = $original_width * $pixel_density_int; |
||
| 40 | $retina_height = $original_height * $pixel_density_int; |
||
| 41 | |||
| 42 | //if the new dimensions are smaller than the full size image dimensions then allow the retina thumb |
||
| 43 | if ( $retina_width < $attachment->width && |
||
| 44 | $retina_height < $attachment->height ) { |
||
| 45 | $args['width'] = $retina_width; |
||
| 46 | $args['height'] = $retina_height; |
||
| 47 | |||
| 48 | //build up the retina attributes |
||
| 49 | $srcset[] = $attachment->html_img_src( $args ) . ' ' . $retina_width . 'w'; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | if ( count( $srcset ) ) { |
||
| 55 | $attr['srcset'] = implode( ',', $srcset ); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | return $attr; |
||
| 61 | } |
||
| 62 | } |
||
| 64 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.