| Conditions | 22 |
| Paths | 1228 |
| Total Lines | 95 |
| 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 |
||
| 29 | function resize( $original_image_src, $args, $thumbnail_object ) { |
||
| 30 | global $current_foogallery; |
||
| 31 | global $foogallery_last_generated_thumb_url; |
||
| 32 | |||
| 33 | $arg_defaults = array( |
||
| 34 | 'width' => 0, |
||
| 35 | 'height' => 0, |
||
| 36 | 'crop' => true, |
||
| 37 | 'jpeg_quality' => foogallery_thumbnail_jpeg_quality(), |
||
| 38 | 'thumb_resize_animations' => foogallery_get_setting( 'thumb_resize_animations' ), |
||
| 39 | 'foogallery_attachment_id'=> $thumbnail_object->ID |
||
| 40 | ); |
||
| 41 | |||
| 42 | if ( isset( $current_foogallery ) ) { |
||
| 43 | $arg_defaults['foogallery_id'] = $current_foogallery->ID; |
||
| 44 | } |
||
| 45 | |||
| 46 | $args = wp_parse_args( $args, $arg_defaults ); |
||
| 47 | |||
| 48 | //allow for plugins to change the thumbnail creation args |
||
| 49 | $args = apply_filters( 'foogallery_thumbnail_resize_args', $args, $original_image_src, $thumbnail_object ); |
||
| 50 | |||
| 51 | //check the current arguments passed in by the shortcode |
||
| 52 | global $current_foogallery_arguments; |
||
| 53 | if ( isset( $current_foogallery_arguments ) && isset( $current_foogallery_arguments['template'] ) ) { |
||
| 54 | $thumbnail_args = apply_filters( 'foogallery_calculate_thumbnail_dimensions-' . $current_foogallery_arguments['template'], $args, $current_foogallery_arguments ); |
||
| 55 | $args = wp_parse_args( $thumbnail_args, $args ); |
||
| 56 | } |
||
| 57 | |||
| 58 | $width = (int)$args['width']; |
||
| 59 | $height = (int)$args['height']; |
||
| 60 | $crop = (bool)$args['crop']; |
||
| 61 | |||
| 62 | if ( 0 === $width && 0 === $height ) { |
||
| 63 | return $original_image_src; |
||
| 64 | } |
||
| 65 | |||
| 66 | //we can force the use of the originally uploaded full-size image |
||
| 67 | $force_use_original_image = isset( $args['force_use_original_image'] ) && true === $args['force_use_original_image']; |
||
| 68 | |||
| 69 | if ( $force_use_original_image ) { |
||
| 70 | $fullsize = wp_get_attachment_image_src( $thumbnail_object->ID, 'fullsize' ); |
||
| 71 | |||
| 72 | return $fullsize[0]; |
||
| 73 | } |
||
| 74 | |||
| 75 | //we can force the use of the original WP icon or WP-generated thumb by passing through args individually |
||
| 76 | $force_use_original_thumb = isset( $args['force_use_original_thumb'] ) && true === $args['force_use_original_thumb']; |
||
| 77 | |||
| 78 | if ( $force_use_original_thumb ) { |
||
| 79 | $thumbnail_icon = wp_get_attachment_image_src( $thumbnail_object->ID, array( $width, $height ) ); |
||
| 80 | |||
| 81 | return $thumbnail_icon[0]; |
||
| 82 | } |
||
| 83 | |||
| 84 | //we can force the use of original WP thumbs by passing through args individually, or by saved settings |
||
| 85 | $use_original_thumbs = ( isset( $args['use_original_thumbs'] ) && true === $args['use_original_thumbs'] ) || 'on' === foogallery_get_setting( 'use_original_thumbs' ); |
||
| 86 | |||
| 87 | if ( $use_original_thumbs ) { |
||
| 88 | |||
| 89 | $option_thumbnail_size_w = get_option( 'thumbnail_size_w' ); |
||
| 90 | $option_thumbnail_size_h = get_option( 'thumbnail_size_h' ); |
||
| 91 | $option_thumbnail_crop = get_option( 'thumbnail_crop' ); |
||
| 92 | |||
| 93 | //check if we are trying to get back the default thumbnail that we already have |
||
| 94 | if ( $thumbnail_object->ID > 0 && $width == $option_thumbnail_size_w && $height == $option_thumbnail_size_h && $crop == $option_thumbnail_crop ) { |
||
| 95 | $thumbnail_attributes = wp_get_attachment_image_src( $thumbnail_object->ID ); |
||
| 96 | |||
| 97 | return $thumbnail_attributes[0]; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | if ( $thumbnail_object->ID > 0 ) { |
||
| 102 | $crop_from_position = get_post_meta( $thumbnail_object->ID, 'wpthumb_crop_pos', true ); |
||
| 103 | |||
| 104 | if ( !empty( $crop_from_position ) ) { |
||
| 105 | $args['crop_from_position'] = $crop_from_position; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | //remove invalid resize args |
||
| 110 | if ( array_key_exists( 'height', $args ) && 0 === $args['height'] ) { |
||
| 111 | unset( $args['height'] ); |
||
| 112 | } |
||
| 113 | |||
| 114 | //do some checks to see if the image is smaller |
||
| 115 | if ( $this->should_resize( $thumbnail_object, $args ) ) { |
||
| 116 | //save the generated thumb url to a global so that we can use it later if needed |
||
| 117 | $foogallery_last_generated_thumb_url = wpthumb( $original_image_src, $args ); |
||
| 118 | } else { |
||
| 119 | $foogallery_last_generated_thumb_url = $original_image_src; |
||
| 120 | } |
||
| 121 | |||
| 122 | return $foogallery_last_generated_thumb_url; |
||
| 123 | } |
||
| 124 | |||
| 191 |
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.