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.

get_thumbnail_dimensions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
if ( !class_exists( 'FooGallery_Default_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_DEFAULT_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Default_Gallery_Template {
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...
8
		/**
9
		 * Wire up everything we need to run the extension
10
		 */
11
		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...
12
			add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) );
13
14
			add_action( 'foogallery_located_template-default', array( $this, 'enqueue_dependencies' ) );
15
16
			add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
17
18
			//build up any preview arguments
19
			add_filter( 'foogallery_preview_arguments-default', array( $this, 'preview_arguments' ), 10, 2 );
20
21
			//build up the thumb dimensions from some arguments
22
			add_filter( 'foogallery_calculate_thumbnail_dimensions-default', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
23
24
			//build up the thumb dimensions on save
25
			add_filter( 'foogallery_template_thumbnail_dimensions-default', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
26
27
			//build up the arguments needed for rendering this template
28
			add_filter( 'foogallery_gallery_template_arguments-default', array( $this, 'build_gallery_template_arguments' ) );
29
		}
30
31
		/**
32
		 * Register myself so that all associated JS and CSS files can be found and automatically included
33
		 * @param $extensions
34
		 *
35
		 * @return array
36
		 */
37
		function register_myself( $extensions ) {
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...
38
			$extensions[] = __FILE__;
39
			return $extensions;
40
		}
41
42
		/**
43
		 * Add our gallery template to the list of templates available for every gallery
44
		 * @param $gallery_templates
45
		 *
46
		 * @return array
47
		 */
48
		function add_template( $gallery_templates ) {
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...
49
			$gallery_templates[] = array(
50
				'slug'        => 'default',
51
				'name'        => __( 'Responsive Image Gallery', 'foogallery' ),
52
				'preview_support' => true,
53
				'common_fields_support' => true,
54
				'paging_support' => true,
55
				'lazyload_support' => true,
56
				'mandatory_classes' => 'fg-default',
57
				'thumbnail_dimensions' => true,
58
				'filtering_support' => true,
59
				'fields'	  => array(
60
                    array(
61
                        'id'      => 'thumbnail_dimensions',
62
                        'title'   => __( 'Thumbnail Size', 'foogallery' ),
63
                        'desc'    => __( 'Choose the size of your thumbnails.', 'foogallery' ),
64
                        'section' => __( 'General', 'foogallery' ),
65
                        'type'    => 'thumb_size_no_crop',
66
                        'default' => array(
67
                            'width' => get_option( 'thumbnail_size_w' ),
68
                            'height' => get_option( 'thumbnail_size_h' ),
69
                        ),
70
						'row_data'=> array(
71
                            'data-foogallery-change-selector' => 'input',
72
							'data-foogallery-preview' => 'shortcode'
73
						)
74
                    ),
75
                    array(
76
                        'id'      => 'thumbnail_link',
77
                        'title'   => __( 'Link To', 'foogallery' ),
78
                        'section' => __( 'General', 'foogallery' ),
79
                        'default' => 'image',
80
                        'type'    => 'thumb_link',
81
                        'desc'	  => __( 'You can choose to link each thumbnail to the full size image, the image\'s attachment page, a custom URL, or you can choose to not link to anything.', 'foogallery' ),
82
                    ),
83
					array(
84
						'id'      => 'lightbox',
85
						'title'   => __( 'Lightbox', 'foogallery' ),
86
						'desc'    => __( 'Choose which lightbox you want to use. The lightbox will generally only work if you set the thumbnail link to "Full Size Image".', 'foogallery' ),
87
                        'section' => __( 'General', 'foogallery' ),
88
						'type'    => 'lightbox',
89
                        'default' => 'none'
90
					),
91
					array(
92
						'id'      => 'spacing',
93
						'title'   => __( 'Spacing', 'foogallery' ),
94
						'desc'    => __( 'The spacing or gap between thumbnails in the gallery.', 'foogallery' ),
95
                        'section' => __( 'General', 'foogallery' ),
96
						'type'    => 'select',
97
						'default' => 'fg-gutter-10',
98
						'choices' => array(
99
							'fg-gutter-0' => __( 'none', 'foogallery' ),
100
							'fg-gutter-5' => __( '5 pixels', 'foogallery' ),
101
							'fg-gutter-10' => __( '10 pixels', 'foogallery' ),
102
							'fg-gutter-15' => __( '15 pixels', 'foogallery' ),
103
							'fg-gutter-20' => __( '20 pixels', 'foogallery' ),
104
							'fg-gutter-25' => __( '25 pixels', 'foogallery' ),
105
						),
106
                        'row_data'=> array(
107
                            'data-foogallery-change-selector' => 'select',
108
							'data-foogallery-preview' => 'class'
109
                        )
110
					),
111
					array(
112
						'id'      => 'alignment',
113
						'title'   => __( 'Alignment', 'foogallery' ),
114
						'desc'    => __( 'The horizontal alignment of the thumbnails inside the gallery.', 'foogallery' ),
115
                        'section' => __( 'General', 'foogallery' ),
116
						'default' => 'fg-center',
117
						'type'    => 'radio',
118
						'spacer'  => '<span class="spacer"></span>',
119
						'choices' => array(
120
							'fg-left' => __( 'Left', 'foogallery' ),
121
							'fg-center' => __( 'Center', 'foogallery' ),
122
							'fg-right' => __( 'Right', 'foogallery' ),
123
						),
124
                        'row_data'=> array(
125
                            'data-foogallery-change-selector' => 'input:radio',
126
							'data-foogallery-preview' => 'class'
127
                        )
128
					)
129
				)
130
			);
131
132
			return $gallery_templates;
133
		}
134
135
		/**
136
		 * Enqueue scripts that the default gallery template relies on
137
		 */
138
		function enqueue_dependencies( $gallery ) {
0 ignored issues
show
Unused Code introduced by
The parameter $gallery 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...
139
			//enqueue core files
140
			foogallery_enqueue_core_gallery_template_style();
141
			foogallery_enqueue_core_gallery_template_script();
142
		}
143
144
		/**
145
		 * Build up a arguments used in the preview of the gallery
146
		 * @param $args
147
		 * @param $post_data
148
		 *
149
		 * @return mixed
150
		 */
151
		function preview_arguments( $args, $post_data ) {
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...
152
			$args['thumbnail_dimensions'] = $post_data[FOOGALLERY_META_SETTINGS]['default_thumbnail_dimensions'];
153
			return $args;
154
		}
155
156
		/**
157
		 * Builds thumb dimensions from arguments
158
		 *
159
		 * @param array $dimensions
160
		 * @param array $arguments
161
		 *
162
		 * @return mixed
163
		 */
164
		function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) {
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...
165
            if ( array_key_exists( 'thumbnail_dimensions', $arguments) ) {
166
                return array(
167
                    'height' => intval($arguments['thumbnail_dimensions']['height']),
168
                    'width' => intval($arguments['thumbnail_dimensions']['width']),
169
                    'crop' => '1'
170
                );
171
            }
172
            return null;
173
		}
174
175
		/**
176
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
177
		 *
178
		 * @param array $dimensions
179
		 * @param FooGallery $foogallery
180
		 *
181
		 * @return mixed
182
		 */
183
		function get_thumbnail_dimensions( $dimensions, $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...
184
			$dimensions = $foogallery->get_meta( 'default_thumbnail_dimensions', array(
185
				'width' => get_option( 'thumbnail_size_w' ),
186
				'height' => get_option( 'thumbnail_size_h' )
187
			) );
188
			$dimensions['crop'] = true;
189
			return $dimensions;
190
		}
191
192
        /**
193
         * Build up the arguments needed for rendering this gallery template
194
         *
195
         * @param $args
196
         * @return array
197
         */
198
		function build_gallery_template_arguments( $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args 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...
199
            $args = foogallery_gallery_template_setting( 'thumbnail_dimensions', array() );
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
200
            $args['crop'] = '1'; //we now force thumbs to be cropped
201
            $args['link'] = foogallery_gallery_template_setting( 'thumbnail_link', 'image' );
202
203
            return $args;
204
        }
205
	}
206
}