GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — feature/thumb-dimensions ( 3a26b7...7f492d )
by Brad
02:20
created

FooGallery_Thumbnail_Dimensions   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
B calculate_thumbnail_dimensions() 0 29 2
A load_thumbnail_dimensions() 0 12 3
1
<?php
2
/**
3
 * Class to calculate thumb dimensions for a gallery
4
 * Date: 21/03/2017
5
 */
6
if ( ! class_exists( 'FooGallery_Thumbnail_Dimensions' ) ) {
7
8
	class FooGallery_Thumbnail_Dimensions {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
		function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
			if ( is_admin() ) {
12
				add_action( 'foogallery_after_save_gallery', array( $this, 'calculate_thumbnail_dimensions' ), 9, 2 );
13
			}
14
15
			add_filter( 'foogallery_attachment_load', array( $this, 'load_thumbnail_dimensions' ), 10, 2 );
16
		}
17
18
		/**
19
		 * Calculate the exact thumb size for the gallery and save the meta data
20
		 * @param $post_id
21
		 * @param $form_post
22
		 */
23
		function calculate_thumbnail_dimensions( $post_id, $form_post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
			$foogallery = FooGallery::get_by_id( $post_id );
25
26
			$gallery_template = $foogallery->gallery_template;
27
28
			$setting_key = "{$gallery_template}_thumbnail_dimensions";
29
30
			$thumbnail_dimensions = apply_filters( 'foogallery_template_thumbnail_dimensions-' . $gallery_template, $foogallery->get_meta( $setting_key, false ), $foogallery );
31
32
			foreach ( $foogallery->attachments() as $attachment ) {
33
				//$thumbnail_dimensions
34
				$thumb_width = (int) $thumbnail_dimensions['width'];
35
				$thumb_height = (int) $thumbnail_dimensions['height'];
36
				$thumb_crop = (bool) $thumbnail_dimensions['crop'];
37
38
				$size_array = image_resize_dimensions( $attachment->width, $attachment->height, $thumb_width, $thumb_height, $thumb_crop );
39
40
				$size = array(
41
					'width'  => $size_array[4],
42
					'height' => $size_array[5]
43
				);
44
45
				$existing_size = get_post_meta( $attachment->ID, FOOGALLERY_META_THUMB_DIMENSIONS, true );
46
				$existing_size[$foogallery->ID] = $size;
47
48
				//save the post meta against the attachment
49
				update_post_meta( $attachment->ID, FOOGALLERY_META_THUMB_DIMENSIONS, $existing_size );
50
			}
51
		}
52
53
		function load_thumbnail_dimensions( $foogallery_attachment, $foogallery ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
54
			$size = get_post_meta( $foogallery_attachment->ID, FOOGALLERY_META_THUMB_DIMENSIONS, true );
55
			if ( $size && array_key_exists( $foogallery->ID, $size ) ) {
56
				$size = $size[$foogallery->ID];
57
58
				$foogallery_attachment->foogallery_id = $foogallery->ID;
59
				$foogallery_attachment->thumb_width = $size['width'];
60
				$foogallery_attachment->thumb_height = $size['width'];
61
			}
62
63
			return $foogallery_attachment;
64
		}
65
	}
66
}