Test Failed
Push — master ( b3899f...f31e84 )
by Ravinder
05:53
created
includes/class-give-background-updater.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  * @category Class
12 12
  * @author   WordImpress
13 13
  */
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
@@ -54,12 +54,12 @@  discard block
 block discarded – undo
54 54
 	 * and data exists in the queue.
55 55
 	 */
56 56
 	public function handle_cron_healthcheck() {
57
-		if ( $this->is_process_running() ) {
57
+		if ($this->is_process_running()) {
58 58
 			// Background process already running.
59 59
 			return;
60 60
 		}
61 61
 
62
-		if ( $this->is_queue_empty() ) {
62
+		if ($this->is_queue_empty()) {
63 63
 			// No data to process.
64 64
 			$this->clear_scheduled_event();
65 65
 
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	 * Schedule fallback event.
74 74
 	 */
75 75
 	protected function schedule_event() {
76
-		if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
77
-			wp_schedule_event( time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier );
76
+		if ( ! wp_next_scheduled($this->cron_hook_identifier)) {
77
+			wp_schedule_event(time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier);
78 78
 		}
79 79
 	}
80 80
 
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @return mixed
92 92
 	 */
93
-	protected function task( $update ) {
94
-		if ( empty( $update ) ) {
93
+	protected function task($update) {
94
+		if (empty($update)) {
95 95
 			return false;
96 96
 		}
97 97
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 				'update_info' => $update,
106 106
 				'step'        => 1,
107 107
 				'update'      => 1,
108
-				'heading'     => sprintf( 'Update %s of {update_count}', 1 ),
108
+				'heading'     => sprintf('Update %s of {update_count}', 1),
109 109
 				'percentage'  => $give_updates->percentage,
110 110
 			)
111 111
 		);
@@ -113,30 +113,30 @@  discard block
 block discarded – undo
113 113
 		// Continuously skip update if previous update does not complete yet.
114 114
 		if (
115 115
 			$resume_update['update_info']['id'] !== $update['id'] &&
116
-			! give_has_upgrade_completed( $resume_update['update_info']['id'] )
116
+			! give_has_upgrade_completed($resume_update['update_info']['id'])
117 117
 		) {
118 118
 			$batch = Give_Updates::$background_updater->get_all_batch();
119
-			$batch_data_count = count( $batch->data );
119
+			$batch_data_count = count($batch->data);
120 120
 
121
-			if ( ! empty( $batch ) &&  1 === $batch_data_count ) {
122
-				if ( ! empty( $update['depend'] ) ) {
121
+			if ( ! empty($batch) && 1 === $batch_data_count) {
122
+				if ( ! empty($update['depend'])) {
123 123
 
124 124
 					$give_updates   = Give_Updates::get_instance();
125
-					$all_updates    = $give_updates->get_updates( 'database', 'all' );
126
-					$all_update_ids = wp_list_pluck( $all_updates, 'id' );
125
+					$all_updates    = $give_updates->get_updates('database', 'all');
126
+					$all_update_ids = wp_list_pluck($all_updates, 'id');
127 127
 
128
-					foreach ( $update['depend'] as $depend ) {
129
-						if ( give_has_upgrade_completed( $depend ) ) {
128
+					foreach ($update['depend'] as $depend) {
129
+						if (give_has_upgrade_completed($depend)) {
130 130
 							continue;
131 131
 						}
132 132
 
133
-						if ( in_array( $depend, $all_update_ids ) ) {
134
-							array_unshift( $batch->data, $all_updates[ array_search( $depend, $all_update_ids ) ] );
133
+						if (in_array($depend, $all_update_ids)) {
134
+							array_unshift($batch->data, $all_updates[array_search($depend, $all_update_ids)]);
135 135
 						}
136 136
 					}
137 137
 
138
-					if( $batch_data_count !== count( $batch->data ) ) {
139
-						update_option( $batch->key, $batch->data );
138
+					if ($batch_data_count !== count($batch->data)) {
139
+						update_option($batch->key, $batch->data);
140 140
 						$this->dispatch();
141 141
 
142 142
 						wp_die();
@@ -150,15 +150,15 @@  discard block
 block discarded – undo
150 150
 
151 151
 		// Set params.
152 152
 		$resume_update['update_info'] = $update;
153
-		$give_updates->step           = absint( $resume_update['step'] );
154
-		$give_updates->update         = absint( $resume_update['update'] );
155
-		$is_parent_update_completed   = $give_updates->is_parent_updates_completed( $update );
153
+		$give_updates->step           = absint($resume_update['step']);
154
+		$give_updates->update         = absint($resume_update['update']);
155
+		$is_parent_update_completed   = $give_updates->is_parent_updates_completed($update);
156 156
 
157 157
 
158 158
 		// Skip update if dependency update does not complete yet.
159
-		if ( empty( $is_parent_update_completed ) ) {
159
+		if (empty($is_parent_update_completed)) {
160 160
 			// @todo: set error when you have only one update with invalid dependency
161
-			if ( ! is_null( $is_parent_update_completed ) ) {
161
+			if ( ! is_null($is_parent_update_completed)) {
162 162
 				return $update;
163 163
 			}
164 164
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		Give_Cache::disable();
170 170
 
171 171
 		// Run update.
172
-		if ( is_array( $update['callback'] ) ) {
172
+		if (is_array($update['callback'])) {
173 173
 			$update['callback'][0]->$update['callback'][1]();
174 174
 		} else {
175 175
 			$update['callback']();
@@ -178,21 +178,21 @@  discard block
 block discarded – undo
178 178
 		// Set update info.
179 179
 		$doing_upgrade_args = array(
180 180
 			'update_info'      => $update,
181
-			'step'             => ++ $give_updates->step,
181
+			'step'             => ++$give_updates->step,
182 182
 			'update'           => $give_updates->update,
183
-			'heading'          => sprintf( 'Update %s of %s', $give_updates->update, get_option( 'give_db_update_count' ) ),
183
+			'heading'          => sprintf('Update %s of %s', $give_updates->update, get_option('give_db_update_count')),
184 184
 			'percentage'       => $give_updates->percentage,
185 185
 			'total_percentage' => $give_updates->get_db_update_processing_percentage(),
186 186
 		);
187 187
 
188 188
 		// Cache upgrade.
189
-		update_option( 'give_doing_upgrade', $doing_upgrade_args );
189
+		update_option('give_doing_upgrade', $doing_upgrade_args);
190 190
 
191 191
 		// Enable cache.
192 192
 		Give_Cache::enable();
193 193
 
194 194
 		// Check if current update completed or not.
195
-		if ( give_has_upgrade_completed( $update['id'] ) ) {
195
+		if (give_has_upgrade_completed($update['id'])) {
196 196
 			return false;
197 197
 		}
198 198
 
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
 	protected function complete() {
209 209
 		parent::complete();
210 210
 
211
-		delete_option( 'give_db_update_count' );
212
-		delete_option( 'give_doing_upgrade' );
213
-		add_option( 'give_show_db_upgrade_complete_notice', 1, '', 'no' );
211
+		delete_option('give_db_update_count');
212
+		delete_option('give_doing_upgrade');
213
+		add_option('give_show_db_upgrade_complete_notice', 1, '', 'no');
214 214
 	}
215 215
 
216 216
 	/**
@@ -219,18 +219,18 @@  discard block
 block discarded – undo
219 219
 	 * @return int
220 220
 	 */
221 221
 	protected function get_memory_limit() {
222
-		if ( function_exists( 'ini_get' ) ) {
223
-			$memory_limit = ini_get( 'memory_limit' );
222
+		if (function_exists('ini_get')) {
223
+			$memory_limit = ini_get('memory_limit');
224 224
 		} else {
225 225
 			// Sensible default.
226 226
 			$memory_limit = '128M';
227 227
 		}
228 228
 
229
-		if ( ! $memory_limit || '-1' === $memory_limit ) {
229
+		if ( ! $memory_limit || '-1' === $memory_limit) {
230 230
 			// Unlimited, set to 32GB.
231 231
 			$memory_limit = '32000M';
232 232
 		}
233 233
 
234
-		return intval( $memory_limit ) * 1024 * 1024;
234
+		return intval($memory_limit) * 1024 * 1024;
235 235
 	}
236 236
 }
Please login to merge, or discard this patch.
includes/admin/upgrades/class-give-updates.php 1 patch
Spacing   +130 added lines, -136 removed lines patch added patch discarded remove patch
@@ -80,34 +80,34 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @param array $args
82 82
 	 */
83
-	public function register( $args ) {
83
+	public function register($args) {
84 84
 		$args_default = array(
85 85
 			'id'       => '',
86 86
 			'version'  => '',
87 87
 			'callback' => '',
88 88
 		);
89 89
 
90
-		$args = wp_parse_args( $args, $args_default );
90
+		$args = wp_parse_args($args, $args_default);
91 91
 
92 92
 		// You can only register database upgrade.
93 93
 		$args['type'] = 'database';
94 94
 
95 95
 		// Bailout.
96 96
 		if (
97
-			empty( $args['id'] ) ||
98
-			empty( $args['version'] ) ||
99
-			empty( $args['callback'] ) ||
100
-			! is_callable( $args['callback'] )
97
+			empty($args['id']) ||
98
+			empty($args['version']) ||
99
+			empty($args['callback']) ||
100
+			! is_callable($args['callback'])
101 101
 		) {
102 102
 			return;
103 103
 		}
104 104
 
105 105
 		// Change depend param to array.
106
-		if ( isset( $args['depend'] ) && is_string( $args['depend'] ) ) {
107
-			$args['depend'] = array( $args['depend'] );
106
+		if (isset($args['depend']) && is_string($args['depend'])) {
107
+			$args['depend'] = array($args['depend']);
108 108
 		}
109 109
 
110
-		$this->updates[ $args['type'] ][] = $args;
110
+		$this->updates[$args['type']][] = $args;
111 111
 	}
112 112
 
113 113
 	/**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @return static
119 119
 	 */
120 120
 	static function get_instance() {
121
-		if ( is_null( self::$instance ) ) {
121
+		if (is_null(self::$instance)) {
122 122
 			self::$instance = new self();
123 123
 		}
124 124
 
@@ -136,24 +136,24 @@  discard block
 block discarded – undo
136 136
 		/**
137 137
 		 * Load file
138 138
 		 */
139
-		require_once GIVE_PLUGIN_DIR . 'includes/class-give-background-updater.php';
140
-		require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php';
139
+		require_once GIVE_PLUGIN_DIR.'includes/class-give-background-updater.php';
140
+		require_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/upgrade-functions.php';
141 141
 
142 142
 		self::$background_updater = new Give_Background_Updater();
143 143
 
144 144
 		/**
145 145
 		 * Setup hooks.
146 146
 		 */
147
-		add_action( 'init', array( $this, '__register_upgrade' ), 9999 );
148
-		add_action( 'give_set_upgrade_completed', array( $this, '__flush_resume_updates' ), 9999 );
149
-		add_action( 'wp_ajax_give_db_updates_info', array( $this, '__give_db_updates_info' ) );
150
-		add_action( 'wp_ajax_give_run_db_updates', array( $this, '__give_start_updating' ) );
151
-		add_action( 'admin_init', array( $this, '__redirect_admin' ) );
152
-		add_action( 'admin_notices', array( $this, '__show_notice' ) );
153
-
154
-		if ( is_admin() ) {
155
-			add_action( 'admin_init', array( $this, '__change_donations_label' ), 9999 );
156
-			add_action( 'admin_menu', array( $this, '__register_menu' ), 9999 );
147
+		add_action('init', array($this, '__register_upgrade'), 9999);
148
+		add_action('give_set_upgrade_completed', array($this, '__flush_resume_updates'), 9999);
149
+		add_action('wp_ajax_give_db_updates_info', array($this, '__give_db_updates_info'));
150
+		add_action('wp_ajax_give_run_db_updates', array($this, '__give_start_updating'));
151
+		add_action('admin_init', array($this, '__redirect_admin'));
152
+		add_action('admin_notices', array($this, '__show_notice'));
153
+
154
+		if (is_admin()) {
155
+			add_action('admin_init', array($this, '__change_donations_label'), 9999);
156
+			add_action('admin_menu', array($this, '__register_menu'), 9999);
157 157
 		}
158 158
 	}
159 159
 
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
 		$addons         = give_get_plugins();
168 168
 		$plugin_updates = get_plugin_updates();
169 169
 
170
-		foreach ( $addons as $key => $info ) {
171
-			if ( 'active' != $info['Status'] || 'add-on' != $info['Type'] || empty( $plugin_updates[ $key ] ) ) {
170
+		foreach ($addons as $key => $info) {
171
+			if ('active' != $info['Status'] || 'add-on' != $info['Type'] || empty($plugin_updates[$key])) {
172 172
 				continue;
173 173
 			}
174 174
 
175
-			$this->updates['plugin'][] = array_merge( $info, (array) $plugin_updates[ $key ] );
175
+			$this->updates['plugin'][] = array_merge($info, (array) $plugin_updates[$key]);
176 176
 		}
177 177
 	}
178 178
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	 * @access public
185 185
 	 */
186 186
 	public function __register_upgrade() {
187
-		if ( ! is_admin() ) {
187
+		if ( ! is_admin()) {
188 188
 			return;
189 189
 		}
190 190
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		 *
194 194
 		 * @since 1.8.12
195 195
 		 */
196
-		do_action( 'give_register_updates', $this );
196
+		do_action('give_register_updates', $this);
197 197
 	}
198 198
 
199 199
 	/**
@@ -206,21 +206,20 @@  discard block
 block discarded – undo
206 206
 		global $menu;
207 207
 
208 208
 		// Bailout.
209
-		if ( empty( $menu ) || ! $this->get_total_update_count() ) {
209
+		if (empty($menu) || ! $this->get_total_update_count()) {
210 210
 			return;
211 211
 		}
212 212
 
213
-		foreach ( $menu as $index => $menu_item ) {
214
-			if ( 'edit.php?post_type=give_forms' !== $menu_item[2] ) {
213
+		foreach ($menu as $index => $menu_item) {
214
+			if ('edit.php?post_type=give_forms' !== $menu_item[2]) {
215 215
 				continue;
216 216
 			}
217 217
 
218
-			$menu[ $index ][0] = sprintf(
218
+			$menu[$index][0] = sprintf(
219 219
 				'%1$s <span class="update-plugins"><span class="plugin-count give-update-progress-count">%2$s%3$s</span></span>',
220
-				__( 'Donations', 'give' ),
220
+				__('Donations', 'give'),
221 221
 				$this->is_doing_updates() ?
222
-					$this->get_db_update_processing_percentage() :
223
-					$this->get_total_update_count(),
222
+					$this->get_db_update_processing_percentage() : $this->get_total_update_count(),
224 223
 				$this->is_doing_updates() ? '%' : ''
225 224
 			);
226 225
 
@@ -236,7 +235,7 @@  discard block
 block discarded – undo
236 235
 	 */
237 236
 	public function __register_menu() {
238 237
 		// Bailout.
239
-		if( ! give_test_ajax_works() ) {
238
+		if ( ! give_test_ajax_works()) {
240 239
 			return;
241 240
 		}
242 241
 
@@ -244,17 +243,17 @@  discard block
 block discarded – undo
244 243
 		$this->__register_plugin_addon_updates();
245 244
 
246 245
 		// Bailout.
247
-		if ( ! $this->get_total_update_count() ) {
246
+		if ( ! $this->get_total_update_count()) {
248 247
 			// Show complete update message if still on update setting page.
249
-			if ( isset( $_GET['page'] ) && 'give-updates' === $_GET['page'] ) {
248
+			if (isset($_GET['page']) && 'give-updates' === $_GET['page']) {
250 249
 				// Upgrades
251 250
 				add_submenu_page(
252 251
 					'edit.php?post_type=give_forms',
253
-					esc_html__( 'Give Updates Complete', 'give' ),
254
-					__( 'Updates', 'give' ),
252
+					esc_html__('Give Updates Complete', 'give'),
253
+					__('Updates', 'give'),
255 254
 					'manage_give_settings',
256 255
 					'give-updates',
257
-					array( $this, 'render_complete_page' )
256
+					array($this, 'render_complete_page')
258 257
 				);
259 258
 			}
260 259
 
@@ -264,18 +263,17 @@  discard block
 block discarded – undo
264 263
 		// Upgrades
265 264
 		add_submenu_page(
266 265
 			'edit.php?post_type=give_forms',
267
-			esc_html__( 'Give Updates', 'give' ),
266
+			esc_html__('Give Updates', 'give'),
268 267
 			sprintf(
269 268
 				'%1$s <span class="update-plugins"><span class="plugin-count give-update-progress-count">%2$s%3$s</span></span>',
270
-				__( 'Updates', 'give' ),
269
+				__('Updates', 'give'),
271 270
 				$this->is_doing_updates() ?
272
-					$this->get_db_update_processing_percentage() :
273
-					$this->get_total_update_count(),
271
+					$this->get_db_update_processing_percentage() : $this->get_total_update_count(),
274 272
 				$this->is_doing_updates() ? '%' : ''
275 273
 			),
276 274
 			'manage_give_settings',
277 275
 			'give-updates',
278
-			array( $this, 'render_page' )
276
+			array($this, 'render_page')
279 277
 		);
280 278
 	}
281 279
 
@@ -290,13 +288,13 @@  discard block
 block discarded – undo
290 288
 		// Show db upgrade completed notice.
291 289
 		if (
292 290
 			! wp_doing_ajax() &&
293
-			current_user_can( 'manage_give_settings' ) &&
294
-			get_option( 'give_show_db_upgrade_complete_notice' ) &&
295
-			! isset( $_GET['give-db-update-completed'] )
291
+			current_user_can('manage_give_settings') &&
292
+			get_option('give_show_db_upgrade_complete_notice') &&
293
+			! isset($_GET['give-db-update-completed'])
296 294
 		) {
297
-			delete_option( 'give_show_db_upgrade_complete_notice' );
295
+			delete_option('give_show_db_upgrade_complete_notice');
298 296
 
299
-			wp_redirect( add_query_arg( array( 'give-db-update-completed' => 'give_db_upgrade_completed' ) ) );
297
+			wp_redirect(add_query_arg(array('give-db-update-completed' => 'give_db_upgrade_completed')));
300 298
 			exit();
301 299
 		}
302 300
 	}
@@ -310,28 +308,28 @@  discard block
 block discarded – undo
310 308
 	 */
311 309
 	public function __show_notice() {
312 310
 		// Bailout.
313
-		if ( ! current_user_can( 'manage_give_settings' ) || $this->is_doing_updates() ) {
311
+		if ( ! current_user_can('manage_give_settings') || $this->is_doing_updates()) {
314 312
 			return;
315 313
 		}
316 314
 
317 315
 		// Run DB updates.
318
-		if ( ! empty( $_GET['give-run-db-update'] ) ) {
316
+		if ( ! empty($_GET['give-run-db-update'])) {
319 317
 			$this->run_db_update();
320 318
 		}
321 319
 
322 320
 
323 321
 		// Bailout.
324
-		if ( isset( $_GET['page'] ) && 'give-updates' === $_GET['page'] ) {
322
+		if (isset($_GET['page']) && 'give-updates' === $_GET['page']) {
325 323
 			return;
326 324
 		}
327 325
 
328 326
 		// Show notice if ajax is not working.
329
-		if ( ! give_test_ajax_works() ) {
327
+		if ( ! give_test_ajax_works()) {
330 328
 			Give()->notices->register_notice(
331 329
 				array(
332 330
 					'id'          => 'give_db_upgrade_ajax_inaccessible',
333 331
 					'type'        => 'error',
334
-					'description' => __( 'Give needs to upgrade the database but cannot because AJAX is not functioning properly. Please contact your host and ask them to ensure admin-ajax.php is accessible.', 'give' ),
332
+					'description' => __('Give needs to upgrade the database but cannot because AJAX is not functioning properly. Please contact your host and ask them to ensure admin-ajax.php is accessible.', 'give'),
335 333
 					'show'        => true,
336 334
 				)
337 335
 			);
@@ -340,46 +338,46 @@  discard block
 block discarded – undo
340 338
 		}
341 339
 
342 340
 		// Show db upgrade completed notice.
343
-		if ( ! empty( $_GET['give-db-update-completed'] ) ) {
344
-			Give()->notices->register_notice( array(
341
+		if ( ! empty($_GET['give-db-update-completed'])) {
342
+			Give()->notices->register_notice(array(
345 343
 				'id'          => 'give_db_upgrade_completed',
346 344
 				'type'        => 'updated',
347
-				'description' => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ),
345
+				'description' => __('Give database updates completed successfully. Thank you for updating to the latest version!', 'give'),
348 346
 				'show'        => true,
349
-			) );
347
+			));
350 348
 
351 349
 			// Start update.
352
-		} elseif ( ! empty( $_GET['give-run-db-update'] ) ) {
350
+		} elseif ( ! empty($_GET['give-run-db-update'])) {
353 351
 			$this->run_db_update();
354 352
 
355 353
 			// Show run the update notice.
356
-		} elseif ( $this->get_total_new_db_update_count() ) {
354
+		} elseif ($this->get_total_new_db_update_count()) {
357 355
 			ob_start();
358 356
 			?>
359 357
 			<p>
360
-				<strong><?php _e( 'Database Update', 'give' ); ?></strong>
361
-				&nbsp;&#8211;&nbsp;<?php _e( 'GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a complete backup before proceeding.', 'give' ); ?>
358
+				<strong><?php _e('Database Update', 'give'); ?></strong>
359
+				&nbsp;&#8211;&nbsp;<?php _e('GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a complete backup before proceeding.', 'give'); ?>
362 360
 			</p>
363 361
 			<p class="submit">
364
-				<a href="<?php echo esc_url( add_query_arg( array( 'give-run-db-update' => 1 ), admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-run-update-now">
365
-					<?php _e( 'Run the updater', 'woocommerce' ); ?>
362
+				<a href="<?php echo esc_url(add_query_arg(array('give-run-db-update' => 1), admin_url('edit.php?post_type=give_forms&page=give-updates'))); ?>" class="button button-primary give-run-update-now">
363
+					<?php _e('Run the updater', 'woocommerce'); ?>
366 364
 				</a>
367 365
 			</p>
368 366
 			<script type="text/javascript">
369 367
 				jQuery('.give-run-update-now').click('click', function () {
370
-					return window.confirm('<?php echo esc_js( __( 'It is strongly recommended that you backup your database before proceeding. Do you want to run the update now?', 'give' ) ); ?>'); // jshint ignore:line
368
+					return window.confirm('<?php echo esc_js(__('It is strongly recommended that you backup your database before proceeding. Do you want to run the update now?', 'give')); ?>'); // jshint ignore:line
371 369
 				});
372 370
 			</script>
373 371
 			<?php
374 372
 			$desc_html = ob_get_clean();
375 373
 
376 374
 
377
-			Give()->notices->register_notice( array(
375
+			Give()->notices->register_notice(array(
378 376
 				'id'          => 'give_upgrade_db',
379 377
 				'type'        => 'updated',
380 378
 				'dismissible' => false,
381 379
 				'description' => $desc_html,
382
-			) );
380
+			));
383 381
 		}
384 382
 	}
385 383
 
@@ -390,7 +388,7 @@  discard block
 block discarded – undo
390 388
 	 * @access public
391 389
 	 */
392 390
 	public function render_complete_page() {
393
-		include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades-complete.php';
391
+		include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades-complete.php';
394 392
 	}
395 393
 
396 394
 	/**
@@ -400,7 +398,7 @@  discard block
 block discarded – undo
400 398
 	 * @access public
401 399
 	 */
402 400
 	public function render_page() {
403
-		include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades.php';
401
+		include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades.php';
404 402
 	}
405 403
 
406 404
 	/**
@@ -411,26 +409,26 @@  discard block
 block discarded – undo
411 409
 	 */
412 410
 	private function run_db_update() {
413 411
 		// Bailout.
414
-		if ( $this->is_doing_updates() || ! $this->get_total_new_db_update_count() ) {
412
+		if ($this->is_doing_updates() || ! $this->get_total_new_db_update_count()) {
415 413
 			return;
416 414
 		}
417 415
 
418
-		$updates = $this->get_updates( 'database', 'new' );
416
+		$updates = $this->get_updates('database', 'new');
419 417
 
420
-		foreach ( $updates as $update ) {
421
-			self::$background_updater->push_to_queue( $update );
418
+		foreach ($updates as $update) {
419
+			self::$background_updater->push_to_queue($update);
422 420
 		}
423 421
 
424
-		add_option( 'give_db_update_count', count( $updates ), '', 'no' );
422
+		add_option('give_db_update_count', count($updates), '', 'no');
425 423
 
426
-		add_option( 'give_doing_upgrade', array(
424
+		add_option('give_doing_upgrade', array(
427 425
 			'update_info' => $updates[0],
428 426
 			'step'        => 1,
429 427
 			'update'      => 1,
430
-			'heading'     => sprintf( 'Update %s of %s', 1, count( $updates ) ),
428
+			'heading'     => sprintf('Update %s of %s', 1, count($updates)),
431 429
 			'percentage'  => 0,
432 430
 			'total_percentage'  => 0,
433
-		), '', 'no' );
431
+		), '', 'no');
434 432
 
435 433
 		self::$background_updater->save()->dispatch();
436 434
 	}
@@ -444,11 +442,11 @@  discard block
 block discarded – undo
444 442
 	 */
445 443
 	public function __flush_resume_updates() {
446 444
 		//delete_option( 'give_doing_upgrade' );
447
-		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
445
+		update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION));
448 446
 
449 447
 		// Reset counter.
450 448
 		$this->step = $this->percentage = 0;
451
-		++ $this->update;
449
+		++$this->update;
452 450
 	}
453 451
 
454 452
 
@@ -463,7 +461,7 @@  discard block
 block discarded – undo
463 461
 	public function __give_start_updating() {
464 462
 		// Check permission.
465 463
 		if (
466
-			! current_user_can( 'manage_give_settings' ) ||
464
+			! current_user_can('manage_give_settings') ||
467 465
 			$this->is_doing_updates()
468 466
 		) {
469 467
 			wp_send_json_error();
@@ -471,7 +469,7 @@  discard block
 block discarded – undo
471 469
 
472 470
 		// @todo: validate nonce
473 471
 		// @todo: set http method to post
474
-		if ( empty( $_POST['run_db_update'] ) ) {
472
+		if (empty($_POST['run_db_update'])) {
475 473
 			wp_send_json_error();
476 474
 		}
477 475
 
@@ -490,21 +488,21 @@  discard block
 block discarded – undo
490 488
 	 * @return string
491 489
 	 */
492 490
 	public function __give_db_updates_info() {
493
-		$update_info   = get_option( 'give_doing_upgrade' );
491
+		$update_info   = get_option('give_doing_upgrade');
494 492
 		$response_type = '';
495 493
 
496
-		if ( empty( $update_info ) && ! $this->get_pending_db_update_count() ) {
497
-			$update_info   = array(
498
-				'message'    => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ),
499
-				'heading'    => __( 'Updates Completed.', 'give' ),
494
+		if (empty($update_info) && ! $this->get_pending_db_update_count()) {
495
+			$update_info = array(
496
+				'message'    => __('Give database updates completed successfully. Thank you for updating to the latest version!', 'give'),
497
+				'heading'    => __('Updates Completed.', 'give'),
500 498
 				'percentage' => 0,
501 499
 			);
502 500
 			$response_type = 'success';
503 501
 
504
-			delete_option( 'give_show_db_upgrade_complete_notice' );
502
+			delete_option('give_show_db_upgrade_complete_notice');
505 503
 		}
506 504
 
507
-		$this->send_ajax_response( $update_info, $response_type );
505
+		$this->send_ajax_response($update_info, $response_type);
508 506
 	}
509 507
 
510 508
 	/**
@@ -516,7 +514,7 @@  discard block
 block discarded – undo
516 514
 	 * @param        $data
517 515
 	 * @param string $type
518 516
 	 */
519
-	public function send_ajax_response( $data, $type = '' ) {
517
+	public function send_ajax_response($data, $type = '') {
520 518
 		$default = array(
521 519
 			'message'    => '',
522 520
 			'heading'    => '',
@@ -526,24 +524,24 @@  discard block
 block discarded – undo
526 524
 		);
527 525
 
528 526
 		// Set data.
529
-		$data = wp_parse_args( $data, $default );
527
+		$data = wp_parse_args($data, $default);
530 528
 
531 529
 		// Enable cache.
532 530
 		Give_Cache::enable();
533 531
 
534
-		switch ( $type ) {
532
+		switch ($type) {
535 533
 			case 'success':
536
-				wp_send_json_success( $data );
534
+				wp_send_json_success($data);
537 535
 				break;
538 536
 
539 537
 			case 'error':
540
-				wp_send_json_error( $data );
538
+				wp_send_json_error($data);
541 539
 				break;
542 540
 
543 541
 			default:
544
-				wp_send_json( array(
542
+				wp_send_json(array(
545 543
 					'data' => $data,
546
-				) );
544
+				));
547 545
 				break;
548 546
 		}
549 547
 	}
@@ -557,12 +555,12 @@  discard block
 block discarded – undo
557 555
 	 * @param $total
558 556
 	 * @param $current_total
559 557
 	 */
560
-	public function set_percentage( $total, $current_total ) {
558
+	public function set_percentage($total, $current_total) {
561 559
 		// Set percentage.
562
-		$this->percentage = $total ? ( ( $current_total ) / $total ) * 100 : 0;
560
+		$this->percentage = $total ? (($current_total) / $total) * 100 : 0;
563 561
 
564 562
 		// Verify percentage.
565
-		$this->percentage = ( 100 < $this->percentage ) ? 100 : $this->percentage;
563
+		$this->percentage = (100 < $this->percentage) ? 100 : $this->percentage;
566 564
 	}
567 565
 
568 566
 	/**
@@ -575,23 +573,23 @@  discard block
 block discarded – undo
575 573
 	 *
576 574
 	 * @return bool|null
577 575
 	 */
578
-	public function is_parent_updates_completed( $update ) {
576
+	public function is_parent_updates_completed($update) {
579 577
 		// Bailout.
580
-		if ( empty( $update['depend'] ) ) {
578
+		if (empty($update['depend'])) {
581 579
 			return true;
582 580
 		}
583 581
 
584 582
 		// Check if dependency is valid or not.
585
-		if ( ! $this->has_valid_dependency( $update ) ) {
586
-			error_log( print_r( 'exit 2', true ) . "\n", 3, WP_CONTENT_DIR . '/debug_new.log' );
583
+		if ( ! $this->has_valid_dependency($update)) {
584
+			error_log(print_r('exit 2', true)."\n", 3, WP_CONTENT_DIR.'/debug_new.log');
587 585
 			return null;
588 586
 		}
589 587
 
590 588
 		$is_dependency_completed = true;
591 589
 
592
-		foreach ( $update['depend'] as $depend ) {
590
+		foreach ($update['depend'] as $depend) {
593 591
 
594
-			if ( ! give_has_upgrade_completed( $depend ) ) {
592
+			if ( ! give_has_upgrade_completed($depend)) {
595 593
 				$is_dependency_completed = false;
596 594
 				break;
597 595
 			}
@@ -608,7 +606,7 @@  discard block
 block discarded – undo
608 606
 	 * @return bool
609 607
 	 */
610 608
 	public function is_doing_updates() {
611
-		return (bool) get_option( 'give_doing_upgrade' );
609
+		return (bool) get_option('give_doing_upgrade');
612 610
 	}
613 611
 
614 612
 
@@ -622,7 +620,7 @@  discard block
 block discarded – undo
622 620
 	 *
623 621
 	 * @return bool
624 622
 	 */
625
-	public function has_valid_dependency( $update ) {
623
+	public function has_valid_dependency($update) {
626 624
 		$is_valid_dependency = true;
627 625
 		// $update_ids          = wp_list_pluck( $this->get_updates( 'database', 'all' ), 'id' );
628 626
 		//
@@ -648,32 +646,32 @@  discard block
 block discarded – undo
648 646
 	 *
649 647
 	 * @return array
650 648
 	 */
651
-	public function get_updates( $update_type = '', $status = 'all' ) {
649
+	public function get_updates($update_type = '', $status = 'all') {
652 650
 		// return all updates.
653
-		if ( empty( $update_type ) ) {
651
+		if (empty($update_type)) {
654 652
 			return $this->updates;
655 653
 		}
656 654
 
657 655
 		// Get specific update.
658
-		$updates = ! empty( $this->updates[ $update_type ] ) ? $this->updates[ $update_type ] : array();
656
+		$updates = ! empty($this->updates[$update_type]) ? $this->updates[$update_type] : array();
659 657
 
660 658
 		// Bailout.
661
-		if ( empty( $updates ) ) {
659
+		if (empty($updates)) {
662 660
 			return $updates;
663 661
 		}
664 662
 
665
-		switch ( $status ) {
663
+		switch ($status) {
666 664
 			case 'new':
667 665
 				// Remove already completed updates.
668 666
 				$completed_updates = give_get_completed_upgrades();
669 667
 
670
-				if ( ! empty( $completed_updates ) ) {
671
-					foreach ( $updates as $index => $update ) {
672
-						if ( in_array( $update['id'], $completed_updates ) ) {
673
-							unset( $updates[ $index ] );
668
+				if ( ! empty($completed_updates)) {
669
+					foreach ($updates as $index => $update) {
670
+						if (in_array($update['id'], $completed_updates)) {
671
+							unset($updates[$index]);
674 672
 						}
675 673
 					}
676
-					$updates = array_values( $updates );
674
+					$updates = array_values($updates);
677 675
 				}
678 676
 
679 677
 				break;
@@ -690,7 +688,7 @@  discard block
 block discarded – undo
690 688
 	 * @return int
691 689
 	 */
692 690
 	public function get_total_plugin_update_count() {
693
-		return count( $this->get_updates( 'plugin' ) );
691
+		return count($this->get_updates('plugin'));
694 692
 	}
695 693
 
696 694
 	/**
@@ -705,7 +703,7 @@  discard block
 block discarded – undo
705 703
 		$db_update_count     = $this->get_pending_db_update_count();
706 704
 		$plugin_update_count = $this->get_total_plugin_update_count();
707 705
 
708
-		return ( $db_update_count + $plugin_update_count );
706
+		return ($db_update_count + $plugin_update_count);
709 707
 	}
710 708
 
711 709
 	/**
@@ -717,7 +715,7 @@  discard block
 block discarded – undo
717 715
 	 * @return int
718 716
 	 */
719 717
 	public function get_pending_db_update_count() {
720
-		return count( $this->get_updates( 'database', 'new' ) );
718
+		return count($this->get_updates('database', 'new'));
721 719
 	}
722 720
 
723 721
 	/**
@@ -729,7 +727,7 @@  discard block
 block discarded – undo
729 727
 	 * @return int
730 728
 	 */
731 729
 	public function get_total_db_update_count() {
732
-		return count( $this->get_updates( 'database', 'all' ) );
730
+		return count($this->get_updates('database', 'all'));
733 731
 	}
734 732
 
735 733
 	/**
@@ -742,8 +740,7 @@  discard block
 block discarded – undo
742 740
 	 */
743 741
 	public function get_total_new_db_update_count() {
744 742
 		return $this->is_doing_updates() ?
745
-			get_option( 'give_db_update_count' ) :
746
-			$this->get_pending_db_update_count();
743
+			get_option('give_db_update_count') : $this->get_pending_db_update_count();
747 744
 	}
748 745
 
749 746
 	/**
@@ -755,11 +752,10 @@  discard block
 block discarded – undo
755 752
 	 * @return int
756 753
 	 */
757 754
 	public function get_running_db_update() {
758
-		$current_update = get_option( 'give_doing_upgrade' );
755
+		$current_update = get_option('give_doing_upgrade');
759 756
 
760 757
 		return $this->is_doing_updates() ?
761
-			$current_update['update'] :
762
-			1;
758
+			$current_update['update'] : 1;
763 759
 	}
764 760
 
765 761
 	/**
@@ -771,23 +767,21 @@  discard block
 block discarded – undo
771 767
 	 */
772 768
 	public function get_db_update_processing_percentage() {
773 769
 		// Bailout.
774
-		if ( ! $this->get_total_new_db_update_count() ) {
770
+		if ( ! $this->get_total_new_db_update_count()) {
775 771
 			return 0;
776 772
 		}
777 773
 
778
-		$resume_update            = get_option( 'give_doing_upgrade' );
779
-		$update_count_percentages = ( ( $this->get_running_db_update() - 1 ) / $this->get_total_new_db_update_count() ) * 100;
780
-		$update_percentage_share  = ( 1 / $this->get_total_new_db_update_count() ) * 100;
781
-		$upgrade_percentage       = ( ( $resume_update['percentage'] * $update_percentage_share ) / 100 );
774
+		$resume_update            = get_option('give_doing_upgrade');
775
+		$update_count_percentages = (($this->get_running_db_update() - 1) / $this->get_total_new_db_update_count()) * 100;
776
+		$update_percentage_share  = (1 / $this->get_total_new_db_update_count()) * 100;
777
+		$upgrade_percentage       = (($resume_update['percentage'] * $update_percentage_share) / 100);
782 778
 
783 779
 		$final_percentage = $update_count_percentages + $upgrade_percentage;
784 780
 
785 781
 		return $this->is_doing_updates() ?
786
-			( absint( $final_percentage ) ?
787
-				absint( $final_percentage ) :
788
-				round( $final_percentage, 2 )
789
-			) :
790
-			0;
782
+			(absint($final_percentage) ?
783
+				absint($final_percentage) : round($final_percentage, 2)
784
+			) : 0;
791 785
 	}
792 786
 }
793 787
 
Please login to merge, or discard this patch.