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... ( 52bdc8...4fd2a5 )
by Brad
04:37
created

FooGallery_Upgrade   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 171
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 2
B perform_gallery_settings_upgrade() 0 148 6
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 ) {
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
					)
41
				),
42
				array(
43
					'id' => 'border-style',
44
					'value' => 'border-style-circle-white',
45
					'new' => array(
46
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
47
						array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ),
48
						array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ),
49
						array ( 'id' => 'rounded-corners', 'value' => 'fg-round-full' )
50
					)
51
				),
52
				array(
53
					'id' => 'border-style',
54
					'value' => 'border-style-square-black',
55
					'new' => array(
56
						array ( 'id' => 'theme', 'value' => 'fg-dark' ),
57
						array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ),
58
						array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' )
59
					)
60
				),
61
				array(
62
					'id' => 'border-style',
63
					'value' => 'border-style-circle-black',
64
					'new' => array(
65
						array ( 'id' => 'theme', 'value' => 'fg-dark' ),
66
						array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ),
67
						array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ),
68
						array ( 'id' => 'rounded-corners', 'value' => 'fg-round-full' )
69
					)
70
				),
71
				array(
72
					'id' => 'border-style',
73
					'value' => 'border-style-inset',
74
					'new' => array(
75
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
76
						array ( 'id' => 'inset-shadow', 'value' => 'fg-shadow-inset-large' )
77
					)
78
				),
79
				array(
80
					'id' => 'border-style',
81
					'value' => 'border-style-rounded',
82
					'new' => array(
83
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
84
						array ( 'id' => 'rounded-corners', 'value' => 'fg-round-small' )
85
					)
86
				),
87
				array(
88
					'id' => 'spacing',
89
					'value' => 'spacing-width-0',
90
					'new' => array(
91
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-0' )
92
					)
93
				),
94
				array(
95
					'id' => 'spacing',
96
					'value' => 'spacing-width-5',
97
					'new' => array(
98
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-5' )
99
					)
100
				),
101
				array(
102
					'id' => 'spacing',
103
					'value' => 'spacing-width-10',
104
					'new' => array(
105
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-10' )
106
					)
107
				),
108
				array(
109
					'id' => 'spacing',
110
					'value' => 'spacing-width-15',
111
					'new' => array(
112
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-15' )
113
					)
114
				),
115
				array(
116
					'id' => 'spacing',
117
					'value' => 'spacing-width-20',
118
					'new' => array(
119
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-20' )
120
					)
121
				),
122
				array(
123
					'id' => 'spacing',
124
					'value' => 'spacing-width-25',
125
					'new' => array(
126
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-25' )
127
					)
128
				),
129
130
				array(
131
					'id' => 'alignment',
132
					'value' => 'alignment-left',
133
					'new' => array(
134
						array ( 'id' => 'alignment', 'value' => 'fg-left' )
135
					)
136
				),
137
				array(
138
					'id' => 'alignment',
139
					'value' => 'alignment-center',
140
					'new' => array(
141
						array ( 'id' => 'alignment', 'value' => 'fg-center' )
142
					)
143
				),
144
				array(
145
					'id' => 'alignment',
146
					'value' => 'alignment-right',
147
					'new' => array(
148
						array ( 'id' => 'alignment', 'value' => 'fg-right' )
149
					)
150
				),
151
			);
152
153
			//upgrade all template settings
154
			foreach ( foogallery_gallery_templates() as $template ) {
155
156
				foreach ( $mappings as $mapping ) {
157
158
					$settings_key = "{$template['slug']}_{$mapping['id']}";
159
160
					//check if the settings exists
161
					if ( array_key_exists( $settings_key, $foogallery->settings ) ) {
162
163
						$old_settings_value = $foogallery->settings[$settings_key];
164
165
						if ( $mapping['value'] === $old_settings_value ) {
166
							//we have found a match!
167
168
							foreach ( $mapping['new'] as $setting_to_create ) {
169
								$new_setting_key = "{$template['slug']}_{$setting_to_create['id']}";
170
								$new_setting_value = $setting_to_create['value'];
171
								$foogallery->settings[$new_setting_key] = $new_setting_value;
172
							}
173
						}
174
					}
175
				}
176
			}
177
		}
178
	}
179
}