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 — develop ( ce1d31...26bac9 )
by Brad
03:35 queued 01:21
created

include_thumb_dimension_attributes()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 5
nop 3
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
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
			add_filter( 'foogallery_attachment_html_image_attributes', array( $this, 'include_thumb_dimension_attributes' ), 10, 3 );
17
		}
18
19
		/**
20
		 * Calculate the exact thumb size for the gallery and save the meta data
21
		 * @param $post_id
22
		 * @param $form_post
23
		 */
24
		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...
25
			$foogallery = FooGallery::get_by_id( $post_id );
26
27
			$gallery_template = $foogallery->gallery_template;
28
29
			$setting_key = "{$gallery_template}_thumbnail_dimensions";
30
31
			$thumbnail_dimensions = apply_filters( 'foogallery_template_thumbnail_dimensions-' . $gallery_template, $foogallery->get_meta( $setting_key, false ), $foogallery );
32
33
			foreach ( $foogallery->attachments() as $attachment ) {
34
				//$thumbnail_dimensions
35
				$thumb_width = (int) $thumbnail_dimensions['width'];
36
				$thumb_height = (int) $thumbnail_dimensions['height'];
37
				$thumb_crop = (bool) $thumbnail_dimensions['crop'];
38
39
				$size_array = image_resize_dimensions( $attachment->width, $attachment->height, $thumb_width, $thumb_height, $thumb_crop );
40
41
				$size = array(
42
					'width'  => $size_array[4],
43
					'height' => $size_array[5]
44
				);
45
46
				$existing_size = get_post_meta( $attachment->ID, FOOGALLERY_META_THUMB_DIMENSIONS, true );
47
				$existing_size[$foogallery->ID] = $size;
48
49
				//save the post meta against the attachment
50
				update_post_meta( $attachment->ID, FOOGALLERY_META_THUMB_DIMENSIONS, $existing_size );
51
			}
52
		}
53
54
		/**
55
		 * Load the thumb dimension attributes onto the attachment
56
		 * @param $foogallery_attachment
57
		 * @param $foogallery
58
		 *
59
		 * @return mixed
60
		 */
61
		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...
62
			$size = get_post_meta( $foogallery_attachment->ID, FOOGALLERY_META_THUMB_DIMENSIONS, true );
63
			if ( $size && array_key_exists( $foogallery->ID, $size ) ) {
64
				$size = $size[$foogallery->ID];
65
66
				$foogallery_attachment->foogallery_id = $foogallery->ID;
67
				$foogallery_attachment->thumb_width = $size['width'];
68
				$foogallery_attachment->thumb_height = $size['height'];
69
			}
70
71
			return $foogallery_attachment;
72
		}
73
74
		/**
75
		 * Include the thumb dimension html attributes in the rendered HTML
76
		 *
77
		 * @param $attr
78
		 * @param $args
79
		 * @param $foogallery_attachment
80
		 *
81
		 * @return array
82
		 */
83
		function include_thumb_dimension_attributes( $attr, $args, $foogallery_attachment ) {
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...
84
			if ( isset( $foogallery_attachment->foogallery_id ) ) {
85
				if ( $foogallery_attachment->thumb_width > 0 ) {
86
					$attr['width'] = $foogallery_attachment->thumb_width;
87
				}
88
				if ( $foogallery_attachment->thumb_height > 0 ) {
89
					$attr['height'] = $foogallery_attachment->thumb_height;
90
				}
91
			}
92
93
			return $attr;
94
		}
95
	}
96
}