Conditions | 13 |
Paths | 14 |
Total Lines | 60 |
Code Lines | 33 |
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 |
||
59 | function calculate_all_thumbnail_dimensions( $foogallery ) { |
||
60 | global $current_foogallery; |
||
61 | global $current_foogallery_template; |
||
62 | global $current_foogallery_arguments; |
||
63 | |||
64 | //check if we are dealing with a gallery. This check ensures this is not done for albums |
||
65 | if ( isset( $current_foogallery ) && isset( $current_foogallery_template ) ) { |
||
66 | |||
67 | //first do a check if the template needs thumbnail dimensions calculated |
||
68 | if ($this->does_gallery_template_use_thumbnail_dimensions( $current_foogallery_template ) ) { |
||
69 | |||
70 | //load the thumbnail dimensions specific to the gallery, taking preference to arguments |
||
71 | $thumbnail_dimensions = apply_filters( 'foogallery_calculate_thumbnail_dimensions-' . $current_foogallery_template, array(), $current_foogallery_arguments ); |
||
72 | |||
73 | //if we have no dimensions then load them from the gallery settings |
||
74 | if ( $this->empty_dimensions( $thumbnail_dimensions ) ) { |
||
75 | $thumbnail_dimensions = apply_filters( 'foogallery_template_thumbnail_dimensions-' . $current_foogallery_template, $thumbnail_dimensions, $current_foogallery ); |
||
76 | } |
||
77 | |||
78 | if ( isset( $thumbnail_dimensions ) && is_array( $thumbnail_dimensions ) ) { |
||
79 | |||
80 | //$thumbnail_dimensions |
||
81 | $thumb_width = (int)$thumbnail_dimensions['width']; |
||
82 | $thumb_height = (int)$thumbnail_dimensions['height']; |
||
83 | $thumb_crop = (bool)$thumbnail_dimensions['crop']; |
||
84 | |||
85 | //set the appropriate arguments on the attachments so that they can be |
||
86 | // picked up and used in the 'include_thumb_dimension_attributes' function below |
||
87 | foreach ($foogallery->attachments() as $attachment) { |
||
88 | if ( $thumb_crop && $thumb_width > 0 && $thumb_height > 0 ) { |
||
89 | //we have set width and height and crop = true |
||
90 | //we do not need to calculate the dimensions |
||
91 | $calculated_thumb_width = $thumb_width; |
||
92 | $calculated_thumb_height = $thumb_height; |
||
93 | } else { |
||
94 | $size_array = image_resize_dimensions( $attachment->width, $attachment->height, $thumb_width, $thumb_height, $thumb_crop ); |
||
95 | if ( false !== $size_array ) { |
||
96 | $calculated_thumb_width = $size_array[4]; |
||
97 | $calculated_thumb_height = $size_array[5]; |
||
98 | } else { |
||
99 | $size_array = $this->calculate_dimensions( $attachment->width, $attachment->height, $thumb_width, $thumb_height ); |
||
100 | if ( false !== $size_array ) { |
||
101 | $calculated_thumb_width = $size_array[0]; |
||
102 | $calculated_thumb_height = $size_array[1]; |
||
103 | } else { |
||
104 | //fallback for when we cannot calculate dimensions. Use the originals |
||
105 | $calculated_thumb_width = $attachment->width; |
||
106 | $calculated_thumb_height = $attachment->height; |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | |||
111 | $attachment->has_thumbnail_dimensions = true; |
||
112 | $attachment->thumb_width = $calculated_thumb_width; |
||
113 | $attachment->thumb_height = $calculated_thumb_height; |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | |||
189 | } |
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.