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

add_template()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 89
Code Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 75
nc 1
nop 1
dl 0
loc 89
rs 8.5731
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
if ( !class_exists( 'FooGallery_Justified_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_JUSTIFIED_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Justified_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
			add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
14
15
			add_filter( 'foogallery_template_thumbnail_dimensions-justified', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
16
		}
17
18
		/**
19
		 * Register myself so that all associated JS and CSS files can be found and automatically included
20
		 * @param $extensions
21
		 *
22
		 * @return array
23
		 */
24
		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...
25
			$extensions[] = __FILE__;
26
			return $extensions;
27
		}
28
29
		/**
30
		 * Add our gallery template to the list of templates available for every gallery
31
		 * @param $gallery_templates
32
		 *
33
		 * @return array
34
		 */
35
		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...
36
			$gallery_templates[] = array(
37
					'slug'        => 'justified',
38
					'name'        => __( 'Justified Gallery', 'foogallery' ),
39
					'fields'	  => array(
40
							array(
41
									'id'	  => 'help',
42
									'title'	  => __( 'Tip', 'foogallery' ),
43
									'type'	  => 'html',
44
									'help'	  => true,
45
									'desc'	  => __( 'The Justified Gallery template uses the popular <a href="http://miromannino.com/projects/justified-gallery/" target="_blank">Justified Gallery jQuery Plugin</a> under the hood. You can specify thumbnail captions by setting the alt text for your attachments.', 'foogallery' ),
46
							),
47
							array(
48
									'id'      => 'thumb_height',
49
									'title'   => __( 'Thumb Height', 'foogallery' ),
50
									'desc'    => __( 'Choose the height of your thumbnails. Thumbnails will be generated on the fly and cached once generated.', 'foogallery' ),
51
									'type'    => 'number',
52
									'class'   => 'small-text',
53
									'default' => 250,
54
									'step'    => '10',
55
									'min'     => '0',
56
							),
57
							array(
58
									'id'      => 'row_height',
59
									'title'   => __( 'Row Height', 'foogallery' ),
60
									'desc'    => __( 'The preferred height of your gallery rows. This can be different from the thumbnail height.', 'foogallery' ),
61
									'type'    => 'number',
62
									'class'   => 'small-text',
63
									'default' => 150,
64
									'step'    => '10',
65
									'min'     => '0',
66
							),
67
							array(
68
									'id'      => 'max_row_height',
69
									'title'   => __( 'Max Row Height', 'foogallery' ),
70
									'desc'    => __( 'A number (e.g 200) which specifies the maximum row height in pixels. A negative value for no limits. Alternatively, use a percentage (e.g. 200% which means that the row height cannot exceed 2 * rowHeight)', 'foogallery' ),
71
									'type'    => 'text',
72
									'class'   => 'small-text',
73
									'default' => '200%'
74
							),
75
							array(
76
									'id'      => 'margins',
77
									'title'   => __( 'Margins', 'foogallery' ),
78
									'desc'    => __( 'The spacing between your thumbnails.', 'foogallery' ),
79
									'type'    => 'number',
80
									'class'   => 'small-text',
81
									'default' => 1,
82
									'step'    => '1',
83
									'min'     => '0',
84
							),
85
							array(
86
									'id'      => 'captions',
87
									'title'   => __( 'Show Captions', 'foogallery' ),
88
									'desc'    => __( 'Show a caption when hovering over your thumbnails. (Set captions by adding either a title or alt text to an attachment)', 'foogallery' ),
89
									'type'    => 'checkbox',
90
									'default' => 'on',
91
							),
92
							array(
93
									'id'      => 'caption_source',
94
									'title'   => __( 'Caption Source', 'foogallery' ),
95
									'desc'    => __( 'Pull captions from either the attachment Title, Caption or Alt Text.', 'foogallery' ),
96
									'type'    => 'radio',
97
									'default' => 'title',
98
									'spacer'  => '<span class="spacer"></span>',
99
									'choices' => array(
100
											'title'  => __( 'Attachment Title', 'foogallery' ),
101
											'caption'   => __( 'Attachment Caption', 'foogallery' ),
102
											'alt'   => __( 'Attachment Alt Text', 'foogallery' )
103
									)
104
							),
105
							array(
106
									'id'      => 'thumbnail_link',
107
									'title'   => __( 'Thumbnail Link', 'foogallery' ),
108
									'default' => 'image' ,
109
									'type'    => 'thumb_link',
110
									'spacer'  => '<span class="spacer"></span>',
111
									'desc'	  => __( 'You can choose to link each thumbnail to the full size image, or to the image\'s attachment page, or you can choose to not link to anything.', 'foogallery' ),
112
							),
113
							array(
114
									'id'      => 'lightbox',
115
									'title'   => __( 'Lightbox', 'foogallery' ),
116
									'desc'    => __( 'Choose which lightbox you want to display images with. The lightbox will only work if you set the thumbnail link to "Full Size Image".', 'foogallery' ),
117
									'type'    => 'lightbox',
118
							),
119
					),
120
			);
121
122
			return $gallery_templates;
123
		}
124
125
		/**
126
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
127
		 *
128
		 * @param array $dimensions
129
		 * @param FooGallery $foogallery
130
		 *
131
		 * @return mixed
132
		 */
133
		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...
134
			$height = $foogallery->get_meta( 'justified_thumb_height', false );
135
			return array(
136
				'height' => intval( $height ),
137
				'width'  => 0,
138
				'crop'   => false
139
			);
140
		}
141
	}
142
}