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/gallery-template-clien... ( 6eed57 )
by Brad
02:17
created

functions.php ➔ foogallery_get_gallery_template_common_thumbnail_fields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 94
Code Lines 76

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 76
nc 1
nop 1
dl 0
loc 94
rs 8.4378
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
 * FooGallery default extensions common functions
4
 */
5
6
/***
7
 * Enqueue the imagesLoaded script file
8
 */
9
function foogallery_enqueue_imagesloaded_script() {
10
    global $wp_version;
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...
11
    if ( version_compare( $wp_version, '4.6' ) >= 0 ) {
12
13
        wp_enqueue_script('imagesloaded');
14
15
    } else {
16
17
        //include our own version of imagesLoaded for <4.6
18
        $js = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'js/imagesloaded.pkgd.min.js';
19
        wp_enqueue_script( 'foogallery-imagesloaded', $js, array(), FOOGALLERY_VERSION );
20
    }
21
}
22
23
/**
24
 * Enqueue the core FooGallery stylesheet used by all default templates
25
 */
26
function foogallery_enqueue_core_gallery_template_style() {
27
	$css = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'css/foogallery.min.css';
28
	wp_enqueue_style( 'foogallery-core', $css, array(), FOOGALLERY_VERSION );
29
}
30
31
/**
32
 * Enqueue the core FooGallery script used by all default templates
33
 */
34
function foogallery_enqueue_core_gallery_template_script() {
35
	$js = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'js/foogallery.min.js';
36
	wp_enqueue_script( 'foogallery-core', $js, array(), FOOGALLERY_VERSION );
37
}
38
39
/**
40
 * Add common thumbnail fields to a gallery template
41
 *
42
 * @param $template
43
 *
44
 * @return array
45
 */
46
function foogallery_get_gallery_template_common_thumbnail_fields($gallery_template) {
47
48
	$template = $gallery_template['slug'];
49
50
	$border_style_choices = apply_filters( "foogallery_gallery_template_common_thumbnail_fields_border_style_choices-{$template}",  array(
51
		'border-style-square-white' => array( 'label' => __( 'Square white border with shadow' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/border-style-icon-square-white.png' ),
52
		'border-style-circle-white' => array( 'label' => __( 'Circular white border with shadow' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/border-style-icon-circle-white.png' ),
53
		'border-style-square-black' => array( 'label' => __( 'Square Black' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/border-style-icon-square-black.png' ),
54
		'border-style-circle-black' => array( 'label' => __( 'Circular Black' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/border-style-icon-circle-black.png' ),
55
		'border-style-inset' => array( 'label' => __( 'Square Inset' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/border-style-icon-square-inset.png' ),
56
		'border-style-rounded' => array( 'label' => __( 'Plain Rounded' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/border-style-icon-plain-rounded.png' ),
57
		'' => array( 'label' => __( 'Plain' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/border-style-icon-none.png' ),
58
	) );
59
	$fields[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$fields was never initialized. Although not strictly required by PHP, it is generally a good practice to add $fields = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
60
		'id'      => 'border-style',
61
		'title'   => __( 'Border Style', 'foogallery' ),
62
		'desc'    => __( 'The border style for each thumbnail in the gallery.', 'foogallery' ),
63
		'section' => __( 'Thumbnail Settings', 'foogallery' ),
64
		'type'    => 'icon',
65
		'default' => 'border-style-square-white',
66
		'choices' => $border_style_choices
67
	);
68
69
	$hover_effect_type_choices = apply_filters( "foogallery_gallery_template_common_thumbnail_fields_hover_effect_type_choices-{$template}", array(
70
		''  => __( 'Icon', 'foogallery' ),
71
		'hover-effect-tint'   => __( 'Dark Tint', 'foogallery' ),
72
		'hover-effect-color' => __( 'Colorize', 'foogallery' ),
73
		'hover-effect-caption' => __( 'Caption', 'foogallery' ),
74
		'hover-effect-scale' => __( 'Scale', 'foogallery' ),
75
		'hover-effect-none' => __( 'None', 'foogallery' )
76
	) );
77
	$fields[] = array(
78
		'id'      => 'hover-effect-type',
79
		'title'   => __( 'Hover Effect Type', 'foogallery' ),
80
		'section' => __( 'Thumbnail Settings', 'foogallery' ),
81
		'default' => '',
82
		'type'    => 'radio',
83
		'choices' => $hover_effect_type_choices,
84
		'spacer'  => '<span class="spacer"></span>',
85
		'desc'	  => __( 'The type of hover effect the thumbnails will use.', 'foogallery' ),
86
	);
87
88
	$hover_effect_choices = apply_filters( "foogallery_gallery_template_common_thumbnail_fields_hover_effect_choices-{$template}", array(
89
		'hover-effect-zoom' => array( 'label' => __( 'Zoom' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-zoom.png' ),
90
		'hover-effect-zoom2' => array( 'label' => __( 'Zoom 2' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-zoom2.png' ),
91
		'hover-effect-zoom3' => array( 'label' => __( 'Zoom 3' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-zoom3.png' ),
92
		'hover-effect-plus' => array( 'label' => __( 'Plus' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-plus.png' ),
93
		'hover-effect-circle-plus' => array( 'label' => __( 'Cirlce Plus' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-circle-plus.png' ),
94
		'hover-effect-eye' => array( 'label' => __( 'Eye' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-eye.png' )
95
	) );
96
	$fields[] = array(
97
		'id'      => 'hover-effect',
98
		'title'   => __( 'Icon Hover Effect', 'foogallery' ),
99
		'desc'    => __( 'When the hover effect type of Icon is chosen, you can choose which icon is shown when you hover over each thumbnail.', 'foogallery' ),
100
		'section' => __( 'Thumbnail Settings', 'foogallery' ),
101
		'type'    => 'icon',
102
		'default' => 'hover-effect-zoom',
103
		'choices' => $hover_effect_choices
104
	);
105
106
	$caption_hover_effect_choices = apply_filters( "foogallery_gallery_template_common_thumbnail_fields_caption_hover_effect_choices-{$template}", array(
107
		'hover-caption-simple'  => __( 'Simple', 'foogallery' ),
108
		'hover-caption-full-drop'   => __( 'Drop', 'foogallery' ),
109
		'hover-caption-full-fade' => __( 'Fade In', 'foogallery' ),
110
		'hover-caption-push' => __( 'Push', 'foogallery' ),
111
		'hover-caption-simple-always' => __( 'Always Visible', 'foogallery' )
112
	) );
113
	$fields[] = array(
114
		'id'      => 'caption-hover-effect',
115
		'title'   => __( 'Caption Effect', 'foogallery' ),
116
		'section' => __( 'Thumbnail Settings', 'foogallery' ),
117
		'default' => 'hover-caption-simple',
118
		'type'    => 'radio',
119
		'choices' => $caption_hover_effect_choices,
120
		'spacer'  => '<span class="spacer"></span>'
121
	);
122
123
	$caption_content_choices = apply_filters( "foogallery_gallery_template_common_thumbnail_fields_caption_content_choices-{$template}", array(
124
		'title'  => __( 'Title Only', 'foogallery' ),
125
		'desc'   => __( 'Description Only', 'foogallery' ),
126
		'both' => __( 'Title and Description', 'foogallery' )
127
	) );
128
	$fields[] = array(
129
		'id'      => 'caption-content',
130
		'title'   => __( 'Caption Content', 'foogallery' ),
131
		'section' => __( 'Thumbnail Settings', 'foogallery' ),
132
		'default' => 'title',
133
		'type'    => 'radio',
134
		'choices' => $caption_content_choices,
135
		'spacer'  => '<span class="spacer"></span>'
136
	);
137
138
	return $fields;
139
}