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... ( 2e8a82...140c9b )
by Brad
02:36
created

FooGallery_Upgrade   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 303
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 303
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A upgrade_gallery() 0 8 1
C perform_gallery_settings_upgrade() 0 280 7
1
<?php
2
/**
3
 * Class used to upgrade internal gallery settings when needed
4
 * Date: 19/07/2017
5
 */
6
if ( ! class_exists( 'FooGallery_Upgrade' ) ) {
7
8
	class FooGallery_Upgrade {
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
			//intercept the gallery load and check if we need to upgrade a gallery
12
			add_action( 'foogallery_foogallery_instance_after_load', array( $this, 'upgrade_gallery' ), 10, 2 );
13
		}
14
15
		/**
16
		 * Checks if the gallery needs to be upgraded based on the settings version
17
		 *
18
		 * @param $foogallery FooGallery
19
		 * @param $post
20
		 */
21
		function upgrade_gallery( $foogallery, $post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $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...
22
			//if ( FOOGALLERY_SETTINGS_VERSION !== $foogallery->settings_version ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
				$this->perform_gallery_settings_upgrade( $foogallery );
24
25
				//update the settings version for the gallery
26
				//update_post_meta( $post->ID, FOOGALLERY_META_SETTINGS_VERSION, FOOGALLERY_SETTINGS_VERSION );
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
27
			//}
28
		}
29
30
		function perform_gallery_settings_upgrade( $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...
31
32
			$mappings = array(
33
				array(
34
					'id' => 'border-style',
35
					'value' => 'border-style-square-white',
36
					'new' => array(
37
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
38
						array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ),
39
						array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ),
40
						array ( 'id' => 'rounded-corners', 'value' => '' ),
41
						array ( 'id' => 'inset-shadow', 'value' => '' ),
42
					)
43
				),
44
				array(
45
					'id' => 'border-style',
46
					'value' => 'border-style-circle-white',
47
					'new' => array(
48
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
49
						array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ),
50
						array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ),
51
						array ( 'id' => 'rounded-corners', 'value' => 'fg-round-full' ),
52
						array ( 'id' => 'inset-shadow', 'value' => '' ),
53
					)
54
				),
55
				array(
56
					'id' => 'border-style',
57
					'value' => 'border-style-square-black',
58
					'new' => array(
59
						array ( 'id' => 'theme', 'value' => 'fg-dark' ),
60
						array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ),
61
						array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ),
62
						array ( 'id' => 'rounded-corners', 'value' => '' ),
63
						array ( 'id' => 'inset-shadow', 'value' => '' ),
64
					)
65
				),
66
				array(
67
					'id' => 'border-style',
68
					'value' => 'border-style-circle-black',
69
					'new' => array(
70
						array ( 'id' => 'theme', 'value' => 'fg-dark' ),
71
						array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ),
72
						array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ),
73
						array ( 'id' => 'rounded-corners', 'value' => 'fg-round-full' ),
74
						array ( 'id' => 'inset-shadow', 'value' => '' ),
75
					)
76
				),
77
				array(
78
					'id' => 'border-style',
79
					'value' => 'border-style-inset',
80
					'new' => array(
81
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
82
						array ( 'id' => 'border-size', 'value' => '' ),
83
						array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ),
84
						array ( 'id' => 'rounded-corners', 'value' => '' ),
85
						array ( 'id' => 'inset-shadow', 'value' => 'fg-shadow-inset-large' ),
86
					)
87
				),
88
				array(
89
					'id' => 'border-style',
90
					'value' => 'border-style-rounded',
91
					'new' => array(
92
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
93
						array ( 'id' => 'border-size', 'value' => '' ),
94
						array ( 'id' => 'drop-shadow', 'value' => '' ),
95
						array ( 'id' => 'rounded-corners', 'value' => 'fg-round-small' ),
96
						array ( 'id' => 'inset-shadow', 'value' => '' ),
97
					)
98
				),
99
				array(
100
					'id' => 'border-style',
101
					'value' => '',
102
					'new' => array(
103
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
104
						array ( 'id' => 'border-size', 'value' => '' ),
105
						array ( 'id' => 'drop-shadow', 'value' => '' ),
106
						array ( 'id' => 'rounded-corners', 'value' => '' ),
107
						array ( 'id' => 'inset-shadow', 'value' => '' ),
108
					)
109
				),
110
111
				array(
112
					'id' => 'spacing',
113
					'value' => 'spacing-width-0',
114
					'new' => array(
115
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-0' )
116
					)
117
				),
118
				array(
119
					'id' => 'spacing',
120
					'value' => 'spacing-width-5',
121
					'new' => array(
122
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-5' )
123
					)
124
				),
125
				array(
126
					'id' => 'spacing',
127
					'value' => 'spacing-width-10',
128
					'new' => array(
129
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-10' )
130
					)
131
				),
132
				array(
133
					'id' => 'spacing',
134
					'value' => 'spacing-width-15',
135
					'new' => array(
136
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-15' )
137
					)
138
				),
139
				array(
140
					'id' => 'spacing',
141
					'value' => 'spacing-width-20',
142
					'new' => array(
143
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-20' )
144
					)
145
				),
146
				array(
147
					'id' => 'spacing',
148
					'value' => 'spacing-width-25',
149
					'new' => array(
150
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-25' )
151
					)
152
				),
153
154
				array(
155
					'id' => 'alignment',
156
					'value' => 'alignment-left',
157
					'new' => array(
158
						array ( 'id' => 'alignment', 'value' => 'fg-left' )
159
					)
160
				),
161
				array(
162
					'id' => 'alignment',
163
					'value' => 'alignment-center',
164
					'new' => array(
165
						array ( 'id' => 'alignment', 'value' => 'fg-center' )
166
					)
167
				),
168
				array(
169
					'id' => 'alignment',
170
					'value' => 'alignment-right',
171
					'new' => array(
172
						array ( 'id' => 'alignment', 'value' => 'fg-right' )
173
					)
174
				),
175
176
				array(
177
					'id' => 'loading_animation',
178
					'value' => 'yes',
179
					'new' => array(
180
						array ( 'id' => 'loading_animation', 'value' => 'fg-loading-default' )
181
					)
182
				),
183
				array(
184
					'id' => 'loading_animation',
185
					'value' => 'no',
186
					'new' => array(
187
						array ( 'id' => 'loading_animation', 'value' => 'fg-loading-none' )
188
					)
189
				),
190
191
192
				array(
193
					'id' => 'hover-effect-type',
194
					'value' => '', //Icon
195
					'new' => array(
196
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' ),
197
						array ( 'id' => 'caption_type', 'value' => 'fg-caption-hover' ),
198
						array ( 'id' => 'caption_hover_effect', 'value' => 'fg-hover-fade'),
199
						array ( 'id' => 'caption_content', 'value' => 'icon')
200
					)
201
				),
202
203
				array(
204
					'id' => 'hover-effect-type',
205
					'value' => 'hover-effect-tint', //Dark Tint
206
					'new' => array(
207
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' ),
208
						array ( 'id' => 'caption_type', 'value' => 'fg-caption-hover' ),
209
						array ( 'id' => 'caption_hover_effect', 'value' => 'fg-hover-fade')
210
					)
211
				),
212
213
				array(
214
					'id' => 'hover-effect-type',
215
					'value' => 'hover-effect-color', //Colorize
216
					'new' => array(
217
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' ),
218
						array ( 'id' => 'caption_type', 'value' => 'fg-caption-hover' )
219
					)
220
				),
221
222
				array(
223
					'id' => 'hover-effect-type',
224
					'value' => 'hover-effect-none', //None
225
					'new' => array(
226
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' ),
227
						array ( 'id' => 'caption_type', 'value' => 'fg-caption-hover' )
228
					)
229
				),
230
231
				array(
232
					'id' => 'hover-effect-type',
233
					'value' => 'hover-effect-caption', //Caption
234
					'new' => array(
235
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' ),
236
						array ( 'id' => 'caption_type', 'value' => 'fg-caption-hover' )
237
					)
238
				),
239
240
241
242
				array(
243
					'id' => 'caption-hover-effect',
244
					'value' => 'hover-caption-simple',
245
					'new' => array(
246
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' ),
247
						array ( 'id' => 'caption_type', 'value' => 'fg-caption-hover' )
248
					)
249
				),
250
				array(
251
					'id' => 'caption-hover-effect',
252
					'value' => 'hover-caption-full-drop',
253
					'new' => array(
254
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' ),
255
						array ( 'id' => 'caption_hover_effect', 'value' => 'fg-hover-slide-down')
256
					)
257
				),
258
				array(
259
					'id' => 'caption-hover-effect',
260
					'value' => 'hover-caption-full-fade',
261
					'new' => array(
262
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' )
263
					)
264
				),
265
				array(
266
					'id' => 'caption-hover-effect',
267
					'value' => 'hover-caption-push',
268
					'new' => array(
269
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' )
270
					)
271
				),
272
				array(
273
					'id' => 'caption-hover-effect',
274
					'value' => 'hover-caption-simple-always',
275
					'new' => array(
276
						array ( 'id' => 'caption_theme', 'value' => 'fg-custom' )
277
					)
278
				),
279
			);
280
281
			if ( $foogallery->settings ) {
282
283
				//upgrade all template settings
284
				foreach ( foogallery_gallery_templates() as $template ) {
285
286
					foreach ( $mappings as $mapping ) {
287
288
						$settings_key = "{$template['slug']}_{$mapping['id']}";
289
290
						//check if the settings exists
291
						if ( array_key_exists( $settings_key, $foogallery->settings ) ) {
292
293
							$old_settings_value = $foogallery->settings[$settings_key];
294
295
							if ( $mapping['value'] === $old_settings_value ) {
296
								//we have found a match!
297
298
								foreach ( $mapping['new'] as $setting_to_create ) {
299
									$new_setting_key                        = "{$template['slug']}_{$setting_to_create['id']}";
300
									$new_setting_value                      = $setting_to_create['value'];
301
									$foogallery->settings[$new_setting_key] = $new_setting_value;
302
								}
303
							}
304
						}
305
					}
306
				}
307
308
			}
309
		}
310
	}
311
}