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 ( be08aa...a173df )
by Brad
02:49
created

add_template()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 82
Code Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 67
nc 1
nop 1
dl 0
loc 82
rs 8.7769
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_Simple_Portfolio_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_SIMPLE_PORTFOLIO_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Simple_Portfolio_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
			add_filter( 'foogallery_attachment_html_image_attributes', array( $this, 'strip_size' ), 99, 3 );
15
		}
16
17
		/**
18
		 * Register myself so that all associated JS and CSS files can be found and automatically included
19
		 * @param $extensions
20
		 *
21
		 * @return array
22
		 */
23
		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...
24
			$extensions[] = __FILE__;
25
			return $extensions;
26
		}
27
28
		/**
29
		 * Add our gallery template to the list of templates available for every gallery
30
		 * @param $gallery_templates
31
		 *
32
		 * @return array
33
		 */
34
		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...
35
36
			$gallery_templates[] = array(
37
					'slug'        => 'simple_portfolio',
38
					'name'        => __( 'Simple Portfolio', 'foogallery' ),
39
					'fields'	  => array(
40
							array(
41
									'id'	  => 'help',
42
									'title'	  => __( 'Tip', 'foogallery' ),
43
									'type'	  => 'html',
44
									'help'	  => true,
45
									'desc'	  => __( 'The Simple Portfolio template works best when you have <strong>captions and descriptions</strong> set for every attachment in the gallery.<br />To change captions and descriptions, simply hover over the thumbnail above and click the "i" icon.', 'foogallery' ),
46
							),
47
							array(
48
									'id'      => 'thumbnail_dimensions',
49
									'title'   => __( 'Thumbnail Size', 'foogallery' ),
50
									'desc'    => __( 'Choose the size of your thumbnails.', 'foogallery' ),
51
									'type'    => 'thumb_size',
52
									'default' => array(
53
											'width' => 250,
54
											'height' => 200,
55
											'crop' => true,
56
									),
57
							),
58
							array(
59
									'id'      => 'thumbnail_link',
60
									'title'   => __( 'Thumbnail Link', 'foogallery' ),
61
									'default' => 'image',
62
									'type'    => 'thumb_link',
63
									'spacer'  => '<span class="spacer"></span>',
64
									'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' )
65
							),
66
							array(
67
									'id'      => 'lightbox',
68
									'title'   => __( 'Lightbox', 'foogallery' ),
69
									'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' ),
70
									'type'    => 'lightbox',
71
							),
72
							array(
73
									'id'      => 'gutter',
74
									'title'   => __( 'Gutter', 'foogallery' ),
75
									'desc'    => __( 'The spacing between each thumbnail in the gallery.', 'foogallery' ),
76
									'type'    => 'number',
77
									'class'   => 'small-text',
78
									'default' => 40,
79
									'step'    => '1',
80
									'min'     => '0',
81
							),
82
							array(
83
								'id'      => 'caption_position',
84
								'title' => __('Caption Position', 'foogallery'),
85
								'desc' => __('Where the captions are displayed in relation to the thumbnail.', 'foogallery'),
86
								'section' => __( 'Caption Settings', 'foogallery' ),
87
								'default' => '',
88
								'type'    => 'radio',
89
								'spacer'  => '<span class="spacer"></span>',
90
								'choices' => array(
91
									'' => __( 'Below', 'foogallery' ),
92
									'bf-captions-above' => __( 'Above', 'foogallery' )
93
								)
94
							),
95
							array(
96
								'id'      => 'caption_bg_color',
97
								'title'   => __( 'Caption Background Color', 'foogallery' ),
98
								'section' => __( 'Caption Settings', 'foogallery' ),
99
								'type'    => 'colorpicker',
100
								'default' => '#fff',
101
								'opacity' => true
102
							),
103
							array(
104
								'id'      => 'caption_text_color',
105
								'title'   => __( 'Caption Text Color', 'foogallery' ),
106
								'section' => __( 'Caption Settings', 'foogallery' ),
107
								'type'    => 'colorpicker',
108
								'default' => '#333',
109
								'opacity' => true
110
							)
111
					),
112
			);
113
114
			return $gallery_templates;
115
		}
116
117
		/**
118
		 * Simple portfolio relies on there being no width or height attributes on the IMG element so strip them out here.
119
		 *
120
		 * @param $attr
121
		 * @param $args
122
		 * @param $attachment
123
		 *
124
		 * @return mixed
125
		 */
126
		function strip_size($attr, $args, $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...
127
			global $current_foogallery_template;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
128
129
			if ( 'simple_portfolio' === $current_foogallery_template ) {
130
				if ( isset($attr['width']) ){
131
					unset($attr['width']);
132
				}
133
				if ( isset($attr['height']) ){
134
					unset($attr['height']);
135
				}
136
			}
137
138
			return $attr;
139
		}
140
	}
141
}