Conditions | 11 |
Paths | 10 |
Total Lines | 48 |
Code Lines | 24 |
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 | $calculated_thumb_width = $size_array[4]; |
||
96 | $calculated_thumb_height = $size_array[5]; |
||
97 | } |
||
98 | |||
99 | $attachment->has_thumbnail_dimensions = true; |
||
100 | $attachment->thumb_width = $calculated_thumb_width; |
||
101 | $attachment->thumb_height = $calculated_thumb_height; |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | |||
138 | } |
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.