Passed
Push — main ( aaef5c...e4c121 )
by TARIQ
71:39
created
packages/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php 1 patch
Spacing   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -45,45 +45,45 @@  discard block
 block discarded – undo
45 45
 	 * @return int Action ID.
46 46
 	 * @throws RuntimeException     Throws exception when saving the action fails.
47 47
 	 */
48
-	public function save_action( ActionScheduler_Action $action, \DateTime $date = null ) {
48
+	public function save_action(ActionScheduler_Action $action, \DateTime $date = null) {
49 49
 		try {
50 50
 
51
-			$this->validate_action( $action );
51
+			$this->validate_action($action);
52 52
 
53 53
 			/** @var \wpdb $wpdb */
54 54
 			global $wpdb;
55 55
 			$data = array(
56 56
 				'hook'                 => $action->get_hook(),
57
-				'status'               => ( $action->is_finished() ? self::STATUS_COMPLETE : self::STATUS_PENDING ),
58
-				'scheduled_date_gmt'   => $this->get_scheduled_date_string( $action, $date ),
59
-				'scheduled_date_local' => $this->get_scheduled_date_string_local( $action, $date ),
60
-				'schedule'             => serialize( $action->get_schedule() ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
61
-				'group_id'             => $this->get_group_id( $action->get_group() ),
57
+				'status'               => ($action->is_finished() ? self::STATUS_COMPLETE : self::STATUS_PENDING),
58
+				'scheduled_date_gmt'   => $this->get_scheduled_date_string($action, $date),
59
+				'scheduled_date_local' => $this->get_scheduled_date_string_local($action, $date),
60
+				'schedule'             => serialize($action->get_schedule()), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
61
+				'group_id'             => $this->get_group_id($action->get_group()),
62 62
 			);
63
-			$args = wp_json_encode( $action->get_args() );
64
-			if ( strlen( $args ) <= static::$max_index_length ) {
63
+			$args = wp_json_encode($action->get_args());
64
+			if (strlen($args) <= static::$max_index_length) {
65 65
 				$data['args'] = $args;
66 66
 			} else {
67
-				$data['args']          = $this->hash_args( $args );
67
+				$data['args']          = $this->hash_args($args);
68 68
 				$data['extended_args'] = $args;
69 69
 			}
70 70
 
71
-			$table_name = ! empty( $wpdb->actionscheduler_actions ) ? $wpdb->actionscheduler_actions : $wpdb->prefix . 'actionscheduler_actions';
72
-			$wpdb->insert( $table_name, $data );
71
+			$table_name = !empty($wpdb->actionscheduler_actions) ? $wpdb->actionscheduler_actions : $wpdb->prefix . 'actionscheduler_actions';
72
+			$wpdb->insert($table_name, $data);
73 73
 			$action_id = $wpdb->insert_id;
74 74
 
75
-			if ( is_wp_error( $action_id ) ) {
76
-				throw new \RuntimeException( $action_id->get_error_message() );
77
-			} elseif ( empty( $action_id ) ) {
78
-				throw new \RuntimeException( $wpdb->last_error ? $wpdb->last_error : __( 'Database error.', 'woocommerce' ) );
75
+			if (is_wp_error($action_id)) {
76
+				throw new \RuntimeException($action_id->get_error_message());
77
+			} elseif (empty($action_id)) {
78
+				throw new \RuntimeException($wpdb->last_error ? $wpdb->last_error : __('Database error.', 'woocommerce'));
79 79
 			}
80 80
 
81
-			do_action( 'action_scheduler_stored_action', $action_id );
81
+			do_action('action_scheduler_stored_action', $action_id);
82 82
 
83 83
 			return $action_id;
84
-		} catch ( \Exception $e ) {
84
+		} catch (\Exception $e) {
85 85
 			/* translators: %s: error message */
86
-			throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'woocommerce' ), $e->getMessage() ), 0 );
86
+			throw new \RuntimeException(sprintf(__('Error saving action: %s', 'woocommerce'), $e->getMessage()), 0);
87 87
 		}
88 88
 	}
89 89
 
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
 	 * @param string $args JSON encoded action args.
94 94
 	 * @return string
95 95
 	 */
96
-	protected function hash_args( $args ) {
97
-		return md5( $args );
96
+	protected function hash_args($args) {
97
+		return md5($args);
98 98
 	}
99 99
 
100 100
 	/**
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
 	 * @param array $args Action args.
104 104
 	 * @return string
105 105
 	 */
106
-	protected function get_args_for_query( $args ) {
107
-		$encoded = wp_json_encode( $args );
108
-		if ( strlen( $encoded ) <= static::$max_index_length ) {
106
+	protected function get_args_for_query($args) {
107
+		$encoded = wp_json_encode($args);
108
+		if (strlen($encoded) <= static::$max_index_length) {
109 109
 			return $encoded;
110 110
 		}
111
-		return $this->hash_args( $encoded );
111
+		return $this->hash_args($encoded);
112 112
 	}
113 113
 	/**
114 114
 	 * Get a group's ID based on its name/slug.
@@ -118,15 +118,15 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @return int The group's ID, if it exists or is created, or 0 if it does not exist and is not created.
120 120
 	 */
121
-	protected function get_group_id( $slug, $create_if_not_exists = true ) {
122
-		if ( empty( $slug ) ) {
121
+	protected function get_group_id($slug, $create_if_not_exists = true) {
122
+		if (empty($slug)) {
123 123
 			return 0;
124 124
 		}
125 125
 		/** @var \wpdb $wpdb */
126 126
 		global $wpdb;
127
-		$group_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT group_id FROM {$wpdb->actionscheduler_groups} WHERE slug=%s", $slug ) );
128
-		if ( empty( $group_id ) && $create_if_not_exists ) {
129
-			$group_id = $this->create_group( $slug );
127
+		$group_id = (int) $wpdb->get_var($wpdb->prepare("SELECT group_id FROM {$wpdb->actionscheduler_groups} WHERE slug=%s", $slug));
128
+		if (empty($group_id) && $create_if_not_exists) {
129
+			$group_id = $this->create_group($slug);
130 130
 		}
131 131
 
132 132
 		return $group_id;
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @return int Group ID.
141 141
 	 */
142
-	protected function create_group( $slug ) {
142
+	protected function create_group($slug) {
143 143
 		/** @var \wpdb $wpdb */
144 144
 		global $wpdb;
145
-		$wpdb->insert( $wpdb->actionscheduler_groups, array( 'slug' => $slug ) );
145
+		$wpdb->insert($wpdb->actionscheduler_groups, array('slug' => $slug));
146 146
 
147 147
 		return (int) $wpdb->insert_id;
148 148
 	}
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 *
155 155
 	 * @return ActionScheduler_Action
156 156
 	 */
157
-	public function fetch_action( $action_id ) {
157
+	public function fetch_action($action_id) {
158 158
 		/** @var \wpdb $wpdb */
159 159
 		global $wpdb;
160 160
 		$data = $wpdb->get_row(
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
 			)
165 165
 		);
166 166
 
167
-		if ( empty( $data ) ) {
167
+		if (empty($data)) {
168 168
 			return $this->get_null_action();
169 169
 		}
170 170
 
171
-		if ( ! empty( $data->extended_args ) ) {
171
+		if (!empty($data->extended_args)) {
172 172
 			$data->args = $data->extended_args;
173
-			unset( $data->extended_args );
173
+			unset($data->extended_args);
174 174
 		}
175 175
 
176 176
 		// Convert NULL dates to zero dates.
@@ -180,16 +180,16 @@  discard block
 block discarded – undo
180 180
 			'last_attempt_gmt',
181 181
 			'last_attempt_gmt',
182 182
 		);
183
-		foreach ( $date_fields as $date_field ) {
184
-			if ( is_null( $data->$date_field ) ) {
183
+		foreach ($date_fields as $date_field) {
184
+			if (is_null($data->$date_field)) {
185 185
 				$data->$date_field = ActionScheduler_StoreSchema::DEFAULT_DATE;
186 186
 			}
187 187
 		}
188 188
 
189 189
 		try {
190
-			$action = $this->make_action_from_db_record( $data );
191
-		} catch ( ActionScheduler_InvalidActionException $exception ) {
192
-			do_action( 'action_scheduler_failed_fetch_action', $action_id, $exception );
190
+			$action = $this->make_action_from_db_record($data);
191
+		} catch (ActionScheduler_InvalidActionException $exception) {
192
+			do_action('action_scheduler_failed_fetch_action', $action_id, $exception);
193 193
 			return $this->get_null_action();
194 194
 		}
195 195
 
@@ -212,21 +212,21 @@  discard block
 block discarded – undo
212 212
 	 *
213 213
 	 * @return ActionScheduler_Action|ActionScheduler_CanceledAction|ActionScheduler_FinishedAction
214 214
 	 */
215
-	protected function make_action_from_db_record( $data ) {
215
+	protected function make_action_from_db_record($data) {
216 216
 
217 217
 		$hook     = $data->hook;
218
-		$args     = json_decode( $data->args, true );
219
-		$schedule = unserialize( $data->schedule ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
218
+		$args     = json_decode($data->args, true);
219
+		$schedule = unserialize($data->schedule); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
220 220
 
221
-		$this->validate_args( $args, $data->action_id );
222
-		$this->validate_schedule( $schedule, $data->action_id );
221
+		$this->validate_args($args, $data->action_id);
222
+		$this->validate_schedule($schedule, $data->action_id);
223 223
 
224
-		if ( empty( $schedule ) ) {
224
+		if (empty($schedule)) {
225 225
 			$schedule = new ActionScheduler_NullSchedule();
226 226
 		}
227 227
 		$group = $data->group ? $data->group : '';
228 228
 
229
-		return ActionScheduler::factory()->get_stored_action( $data->status, $data->hook, $args, $schedule, $group );
229
+		return ActionScheduler::factory()->get_stored_action($data->status, $data->hook, $args, $schedule, $group);
230 230
 	}
231 231
 
232 232
 	/**
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 	 * @return string SQL statement already properly escaped.
241 241
 	 * @throws InvalidArgumentException If the query is invalid.
242 242
 	 */
243
-	protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) {
243
+	protected function get_query_actions_sql(array $query, $select_or_count = 'select') {
244 244
 
245
-		if ( ! in_array( $select_or_count, array( 'select', 'count' ), true ) ) {
246
-			throw new InvalidArgumentException( __( 'Invalid value for select or count parameter. Cannot query actions.', 'woocommerce' ) );
245
+		if (!in_array($select_or_count, array('select', 'count'), true)) {
246
+			throw new InvalidArgumentException(__('Invalid value for select or count parameter. Cannot query actions.', 'woocommerce'));
247 247
 		}
248 248
 
249 249
 		$query = wp_parse_args(
@@ -267,72 +267,72 @@  discard block
 block discarded – undo
267 267
 
268 268
 		/** @var \wpdb $wpdb */
269 269
 		global $wpdb;
270
-		$sql        = ( 'count' === $select_or_count ) ? 'SELECT count(a.action_id)' : 'SELECT a.action_id';
270
+		$sql        = ('count' === $select_or_count) ? 'SELECT count(a.action_id)' : 'SELECT a.action_id';
271 271
 		$sql       .= " FROM {$wpdb->actionscheduler_actions} a";
272 272
 		$sql_params = array();
273 273
 
274
-		if ( ! empty( $query['group'] ) || 'group' === $query['orderby'] ) {
274
+		if (!empty($query['group']) || 'group' === $query['orderby']) {
275 275
 			$sql .= " LEFT JOIN {$wpdb->actionscheduler_groups} g ON g.group_id=a.group_id";
276 276
 		}
277 277
 
278 278
 		$sql .= ' WHERE 1=1';
279 279
 
280
-		if ( ! empty( $query['group'] ) ) {
280
+		if (!empty($query['group'])) {
281 281
 			$sql         .= ' AND g.slug=%s';
282 282
 			$sql_params[] = $query['group'];
283 283
 		}
284 284
 
285
-		if ( $query['hook'] ) {
285
+		if ($query['hook']) {
286 286
 			$sql         .= ' AND a.hook=%s';
287 287
 			$sql_params[] = $query['hook'];
288 288
 		}
289
-		if ( ! is_null( $query['args'] ) ) {
289
+		if (!is_null($query['args'])) {
290 290
 			$sql         .= ' AND a.args=%s';
291
-			$sql_params[] = $this->get_args_for_query( $query['args'] );
291
+			$sql_params[] = $this->get_args_for_query($query['args']);
292 292
 		}
293 293
 
294
-		if ( $query['status'] ) {
294
+		if ($query['status']) {
295 295
 			$statuses     = (array) $query['status'];
296
-			$placeholders = array_fill( 0, count( $statuses ), '%s' );
297
-			$sql         .= ' AND a.status IN (' . join( ', ', $placeholders ) . ')';
298
-			$sql_params   = array_merge( $sql_params, array_values( $statuses ) );
296
+			$placeholders = array_fill(0, count($statuses), '%s');
297
+			$sql         .= ' AND a.status IN (' . join(', ', $placeholders) . ')';
298
+			$sql_params   = array_merge($sql_params, array_values($statuses));
299 299
 		}
300 300
 
301
-		if ( $query['date'] instanceof \DateTime ) {
301
+		if ($query['date'] instanceof \DateTime) {
302 302
 			$date = clone $query['date'];
303
-			$date->setTimezone( new \DateTimeZone( 'UTC' ) );
304
-			$date_string  = $date->format( 'Y-m-d H:i:s' );
305
-			$comparator   = $this->validate_sql_comparator( $query['date_compare'] );
303
+			$date->setTimezone(new \DateTimeZone('UTC'));
304
+			$date_string  = $date->format('Y-m-d H:i:s');
305
+			$comparator   = $this->validate_sql_comparator($query['date_compare']);
306 306
 			$sql         .= " AND a.scheduled_date_gmt $comparator %s";
307 307
 			$sql_params[] = $date_string;
308 308
 		}
309 309
 
310
-		if ( $query['modified'] instanceof \DateTime ) {
310
+		if ($query['modified'] instanceof \DateTime) {
311 311
 			$modified = clone $query['modified'];
312
-			$modified->setTimezone( new \DateTimeZone( 'UTC' ) );
313
-			$date_string  = $modified->format( 'Y-m-d H:i:s' );
314
-			$comparator   = $this->validate_sql_comparator( $query['modified_compare'] );
312
+			$modified->setTimezone(new \DateTimeZone('UTC'));
313
+			$date_string  = $modified->format('Y-m-d H:i:s');
314
+			$comparator   = $this->validate_sql_comparator($query['modified_compare']);
315 315
 			$sql         .= " AND a.last_attempt_gmt $comparator %s";
316 316
 			$sql_params[] = $date_string;
317 317
 		}
318 318
 
319
-		if ( true === $query['claimed'] ) {
319
+		if (true === $query['claimed']) {
320 320
 			$sql .= ' AND a.claim_id != 0';
321
-		} elseif ( false === $query['claimed'] ) {
321
+		} elseif (false === $query['claimed']) {
322 322
 			$sql .= ' AND a.claim_id = 0';
323
-		} elseif ( ! is_null( $query['claimed'] ) ) {
323
+		} elseif (!is_null($query['claimed'])) {
324 324
 			$sql         .= ' AND a.claim_id = %d';
325 325
 			$sql_params[] = $query['claimed'];
326 326
 		}
327 327
 
328
-		if ( ! empty( $query['search'] ) ) {
328
+		if (!empty($query['search'])) {
329 329
 			$sql .= ' AND (a.hook LIKE %s OR (a.extended_args IS NULL AND a.args LIKE %s) OR a.extended_args LIKE %s';
330
-			for ( $i = 0; $i < 3; $i++ ) {
331
-				$sql_params[] = sprintf( '%%%s%%', $query['search'] );
330
+			for ($i = 0; $i < 3; $i++) {
331
+				$sql_params[] = sprintf('%%%s%%', $query['search']);
332 332
 			}
333 333
 
334 334
 			$search_claim_id = (int) $query['search'];
335
-			if ( $search_claim_id ) {
335
+			if ($search_claim_id) {
336 336
 				$sql         .= ' OR a.claim_id = %d';
337 337
 				$sql_params[] = $search_claim_id;
338 338
 			}
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
 			$sql .= ')';
341 341
 		}
342 342
 
343
-		if ( 'select' === $select_or_count ) {
344
-			if ( 'ASC' === strtoupper( $query['order'] ) ) {
343
+		if ('select' === $select_or_count) {
344
+			if ('ASC' === strtoupper($query['order'])) {
345 345
 				$order = 'ASC';
346 346
 			} else {
347 347
 				$order = 'DESC';
348 348
 			}
349
-			switch ( $query['orderby'] ) {
349
+			switch ($query['orderby']) {
350 350
 				case 'hook':
351 351
 					$sql .= " ORDER BY a.hook $order";
352 352
 					break;
@@ -367,15 +367,15 @@  discard block
 block discarded – undo
367 367
 					break;
368 368
 			}
369 369
 
370
-			if ( $query['per_page'] > 0 ) {
370
+			if ($query['per_page'] > 0) {
371 371
 				$sql         .= ' LIMIT %d, %d';
372 372
 				$sql_params[] = $query['offset'];
373 373
 				$sql_params[] = $query['per_page'];
374 374
 			}
375 375
 		}
376 376
 
377
-		if ( ! empty( $sql_params ) ) {
378
-			$sql = $wpdb->prepare( $sql, $sql_params ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
377
+		if (!empty($sql_params)) {
378
+			$sql = $wpdb->prepare($sql, $sql_params); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
379 379
 		}
380 380
 
381 381
 		return $sql;
@@ -393,13 +393,13 @@  discard block
 block discarded – undo
393 393
 	 *
394 394
 	 * @return string|array|null The IDs of actions matching the query. Null on failure.
395 395
 	 */
396
-	public function query_actions( $query = array(), $query_type = 'select' ) {
396
+	public function query_actions($query = array(), $query_type = 'select') {
397 397
 		/** @var wpdb $wpdb */
398 398
 		global $wpdb;
399 399
 
400
-		$sql = $this->get_query_actions_sql( $query, $query_type );
400
+		$sql = $this->get_query_actions_sql($query, $query_type);
401 401
 
402
-		return ( 'count' === $query_type ) ? $wpdb->get_var( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoSql, WordPress.DB.DirectDatabaseQuery.NoCaching
402
+		return ('count' === $query_type) ? $wpdb->get_var($sql) : $wpdb->get_col($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoSql, WordPress.DB.DirectDatabaseQuery.NoCaching
403 403
 	}
404 404
 
405 405
 	/**
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
 		$actions_count_by_status = array();
418 418
 		$action_stati_and_labels = $this->get_status_labels();
419 419
 
420
-		foreach ( $wpdb->get_results( $sql ) as $action_data ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
420
+		foreach ($wpdb->get_results($sql) as $action_data) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
421 421
 			// Ignore any actions with invalid status.
422
-			if ( array_key_exists( $action_data->status, $action_stati_and_labels ) ) {
423
-				$actions_count_by_status[ $action_data->status ] = $action_data->count;
422
+			if (array_key_exists($action_data->status, $action_stati_and_labels)) {
423
+				$actions_count_by_status[$action_data->status] = $action_data->count;
424 424
 			}
425 425
 		}
426 426
 
@@ -435,22 +435,22 @@  discard block
 block discarded – undo
435 435
 	 * @return void
436 436
 	 * @throws \InvalidArgumentException If the action update failed.
437 437
 	 */
438
-	public function cancel_action( $action_id ) {
438
+	public function cancel_action($action_id) {
439 439
 		/** @var \wpdb $wpdb */
440 440
 		global $wpdb;
441 441
 
442 442
 		$updated = $wpdb->update(
443 443
 			$wpdb->actionscheduler_actions,
444
-			array( 'status' => self::STATUS_CANCELED ),
445
-			array( 'action_id' => $action_id ),
446
-			array( '%s' ),
447
-			array( '%d' )
444
+			array('status' => self::STATUS_CANCELED),
445
+			array('action_id' => $action_id),
446
+			array('%s'),
447
+			array('%d')
448 448
 		);
449
-		if ( false === $updated ) {
449
+		if (false === $updated) {
450 450
 			/* translators: %s: action ID */
451
-			throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) );
451
+			throw new \InvalidArgumentException(sprintf(__('Unidentified action %s', 'woocommerce'), $action_id));
452 452
 		}
453
-		do_action( 'action_scheduler_canceled_action', $action_id );
453
+		do_action('action_scheduler_canceled_action', $action_id);
454 454
 	}
455 455
 
456 456
 	/**
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
 	 *
463 463
 	 * @return void
464 464
 	 */
465
-	public function cancel_actions_by_hook( $hook ) {
466
-		$this->bulk_cancel_actions( array( 'hook' => $hook ) );
465
+	public function cancel_actions_by_hook($hook) {
466
+		$this->bulk_cancel_actions(array('hook' => $hook));
467 467
 	}
468 468
 
469 469
 	/**
@@ -473,8 +473,8 @@  discard block
 block discarded – undo
473 473
 	 *
474 474
 	 * @return void
475 475
 	 */
476
-	public function cancel_actions_by_group( $group ) {
477
-		$this->bulk_cancel_actions( array( 'group' => $group ) );
476
+	public function cancel_actions_by_group($group) {
477
+		$this->bulk_cancel_actions(array('group' => $group));
478 478
 	}
479 479
 
480 480
 	/**
@@ -484,16 +484,16 @@  discard block
 block discarded – undo
484 484
 	 *
485 485
 	 * @param array $query_args Query parameters.
486 486
 	 */
487
-	protected function bulk_cancel_actions( $query_args ) {
487
+	protected function bulk_cancel_actions($query_args) {
488 488
 		/** @var \wpdb $wpdb */
489 489
 		global $wpdb;
490 490
 
491
-		if ( ! is_array( $query_args ) ) {
491
+		if (!is_array($query_args)) {
492 492
 			return;
493 493
 		}
494 494
 
495 495
 		// Don't cancel actions that are already canceled.
496
-		if ( isset( $query_args['status'] ) && self::STATUS_CANCELED === $query_args['status'] ) {
496
+		if (isset($query_args['status']) && self::STATUS_CANCELED === $query_args['status']) {
497 497
 			return;
498 498
 		}
499 499
 
@@ -507,16 +507,16 @@  discard block
 block discarded – undo
507 507
 			)
508 508
 		);
509 509
 
510
-		while ( $action_ids ) {
511
-			$action_ids = $this->query_actions( $query_args );
512
-			if ( empty( $action_ids ) ) {
510
+		while ($action_ids) {
511
+			$action_ids = $this->query_actions($query_args);
512
+			if (empty($action_ids)) {
513 513
 				break;
514 514
 			}
515 515
 
516
-			$format     = array_fill( 0, count( $action_ids ), '%d' );
517
-			$query_in   = '(' . implode( ',', $format ) . ')';
516
+			$format     = array_fill(0, count($action_ids), '%d');
517
+			$query_in   = '(' . implode(',', $format) . ')';
518 518
 			$parameters = $action_ids;
519
-			array_unshift( $parameters, self::STATUS_CANCELED );
519
+			array_unshift($parameters, self::STATUS_CANCELED);
520 520
 
521 521
 			$wpdb->query(
522 522
 				$wpdb->prepare(
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
 				)
526 526
 			);
527 527
 
528
-			do_action( 'action_scheduler_bulk_cancel_actions', $action_ids );
528
+			do_action('action_scheduler_bulk_cancel_actions', $action_ids);
529 529
 		}
530 530
 	}
531 531
 
@@ -535,14 +535,14 @@  discard block
 block discarded – undo
535 535
 	 * @param int $action_id Action ID.
536 536
 	 * @throws \InvalidArgumentException If the action deletion failed.
537 537
 	 */
538
-	public function delete_action( $action_id ) {
538
+	public function delete_action($action_id) {
539 539
 		/** @var \wpdb $wpdb */
540 540
 		global $wpdb;
541
-		$deleted = $wpdb->delete( $wpdb->actionscheduler_actions, array( 'action_id' => $action_id ), array( '%d' ) );
542
-		if ( empty( $deleted ) ) {
543
-			throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
541
+		$deleted = $wpdb->delete($wpdb->actionscheduler_actions, array('action_id' => $action_id), array('%d'));
542
+		if (empty($deleted)) {
543
+			throw new \InvalidArgumentException(sprintf(__('Unidentified action %s', 'woocommerce'), $action_id)); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
544 544
 		}
545
-		do_action( 'action_scheduler_deleted_action', $action_id );
545
+		do_action('action_scheduler_deleted_action', $action_id);
546 546
 	}
547 547
 
548 548
 	/**
@@ -552,9 +552,9 @@  discard block
 block discarded – undo
552 552
 	 *
553 553
 	 * @return \DateTime The local date the action is scheduled to run, or the date that it ran.
554 554
 	 */
555
-	public function get_date( $action_id ) {
556
-		$date = $this->get_date_gmt( $action_id );
557
-		ActionScheduler_TimezoneHelper::set_local_timezone( $date );
555
+	public function get_date($action_id) {
556
+		$date = $this->get_date_gmt($action_id);
557
+		ActionScheduler_TimezoneHelper::set_local_timezone($date);
558 558
 		return $date;
559 559
 	}
560 560
 
@@ -566,17 +566,17 @@  discard block
 block discarded – undo
566 566
 	 * @throws \InvalidArgumentException If action cannot be identified.
567 567
 	 * @return \DateTime The GMT date the action is scheduled to run, or the date that it ran.
568 568
 	 */
569
-	protected function get_date_gmt( $action_id ) {
569
+	protected function get_date_gmt($action_id) {
570 570
 		/** @var \wpdb $wpdb */
571 571
 		global $wpdb;
572
-		$record = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d", $action_id ) );
573
-		if ( empty( $record ) ) {
574
-			throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
572
+		$record = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d", $action_id));
573
+		if (empty($record)) {
574
+			throw new \InvalidArgumentException(sprintf(__('Unidentified action %s', 'woocommerce'), $action_id)); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
575 575
 		}
576
-		if ( self::STATUS_PENDING === $record->status ) {
577
-			return as_get_datetime_object( $record->scheduled_date_gmt );
576
+		if (self::STATUS_PENDING === $record->status) {
577
+			return as_get_datetime_object($record->scheduled_date_gmt);
578 578
 		} else {
579
-			return as_get_datetime_object( $record->last_attempt_gmt );
579
+			return as_get_datetime_object($record->last_attempt_gmt);
580 580
 		}
581 581
 	}
582 582
 
@@ -590,15 +590,15 @@  discard block
 block discarded – undo
590 590
 	 *
591 591
 	 * @return ActionScheduler_ActionClaim
592 592
 	 */
593
-	public function stake_claim( $max_actions = 10, \DateTime $before_date = null, $hooks = array(), $group = '' ) {
593
+	public function stake_claim($max_actions = 10, \DateTime $before_date = null, $hooks = array(), $group = '') {
594 594
 		$claim_id = $this->generate_claim_id();
595 595
 
596 596
 		$this->claim_before_date = $before_date;
597
-		$this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group );
598
-		$action_ids              = $this->find_actions_by_claim_id( $claim_id );
597
+		$this->claim_actions($claim_id, $max_actions, $before_date, $hooks, $group);
598
+		$action_ids              = $this->find_actions_by_claim_id($claim_id);
599 599
 		$this->claim_before_date = null;
600 600
 
601
-		return new ActionScheduler_ActionClaim( $claim_id, $action_ids );
601
+		return new ActionScheduler_ActionClaim($claim_id, $action_ids);
602 602
 	}
603 603
 
604 604
 	/**
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 		/** @var \wpdb $wpdb */
611 611
 		global $wpdb;
612 612
 		$now = as_get_datetime_object();
613
-		$wpdb->insert( $wpdb->actionscheduler_claims, array( 'date_created_gmt' => $now->format( 'Y-m-d H:i:s' ) ) );
613
+		$wpdb->insert($wpdb->actionscheduler_claims, array('date_created_gmt' => $now->format('Y-m-d H:i:s')));
614 614
 
615 615
 		return $wpdb->insert_id;
616 616
 	}
@@ -628,39 +628,39 @@  discard block
 block discarded – undo
628 628
 	 * @throws \InvalidArgumentException Throws InvalidArgumentException if group doesn't exist.
629 629
 	 * @throws \RuntimeException Throws RuntimeException if unable to claim action.
630 630
 	 */
631
-	protected function claim_actions( $claim_id, $limit, \DateTime $before_date = null, $hooks = array(), $group = '' ) {
631
+	protected function claim_actions($claim_id, $limit, \DateTime $before_date = null, $hooks = array(), $group = '') {
632 632
 		/** @var \wpdb $wpdb */
633 633
 		global $wpdb;
634 634
 
635 635
 		$now  = as_get_datetime_object();
636
-		$date = is_null( $before_date ) ? $now : clone $before_date;
636
+		$date = is_null($before_date) ? $now : clone $before_date;
637 637
 
638 638
 		// can't use $wpdb->update() because of the <= condition.
639 639
 		$update = "UPDATE {$wpdb->actionscheduler_actions} SET claim_id=%d, last_attempt_gmt=%s, last_attempt_local=%s";
640 640
 		$params = array(
641 641
 			$claim_id,
642
-			$now->format( 'Y-m-d H:i:s' ),
643
-			current_time( 'mysql' ),
642
+			$now->format('Y-m-d H:i:s'),
643
+			current_time('mysql'),
644 644
 		);
645 645
 
646 646
 		$where    = 'WHERE claim_id = 0 AND scheduled_date_gmt <= %s AND status=%s';
647
-		$params[] = $date->format( 'Y-m-d H:i:s' );
647
+		$params[] = $date->format('Y-m-d H:i:s');
648 648
 		$params[] = self::STATUS_PENDING;
649 649
 
650
-		if ( ! empty( $hooks ) ) {
651
-			$placeholders = array_fill( 0, count( $hooks ), '%s' );
652
-			$where       .= ' AND hook IN (' . join( ', ', $placeholders ) . ')';
653
-			$params       = array_merge( $params, array_values( $hooks ) );
650
+		if (!empty($hooks)) {
651
+			$placeholders = array_fill(0, count($hooks), '%s');
652
+			$where       .= ' AND hook IN (' . join(', ', $placeholders) . ')';
653
+			$params       = array_merge($params, array_values($hooks));
654 654
 		}
655 655
 
656
-		if ( ! empty( $group ) ) {
656
+		if (!empty($group)) {
657 657
 
658
-			$group_id = $this->get_group_id( $group, false );
658
+			$group_id = $this->get_group_id($group, false);
659 659
 
660 660
 			// throw exception if no matching group found, this matches ActionScheduler_wpPostStore's behaviour.
661
-			if ( empty( $group_id ) ) {
661
+			if (empty($group_id)) {
662 662
 				/* translators: %s: group name */
663
-				throw new InvalidArgumentException( sprintf( __( 'The group "%s" does not exist.', 'woocommerce' ), $group ) );
663
+				throw new InvalidArgumentException(sprintf(__('The group "%s" does not exist.', 'woocommerce'), $group));
664 664
 			}
665 665
 
666 666
 			$where   .= ' AND group_id = %d';
@@ -674,13 +674,13 @@  discard block
 block discarded – undo
674 674
 		 *
675 675
 		 * @param string $order_by_sql
676 676
 		 */
677
-		$order    = apply_filters( 'action_scheduler_claim_actions_order_by', 'ORDER BY attempts ASC, scheduled_date_gmt ASC, action_id ASC' );
677
+		$order    = apply_filters('action_scheduler_claim_actions_order_by', 'ORDER BY attempts ASC, scheduled_date_gmt ASC, action_id ASC');
678 678
 		$params[] = $limit;
679 679
 
680
-		$sql           = $wpdb->prepare( "{$update} {$where} {$order} LIMIT %d", $params ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders
681
-		$rows_affected = $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
682
-		if ( false === $rows_affected ) {
683
-			throw new \RuntimeException( __( 'Unable to claim actions. Database error.', 'woocommerce' ) );
680
+		$sql           = $wpdb->prepare("{$update} {$where} {$order} LIMIT %d", $params); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders
681
+		$rows_affected = $wpdb->query($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
682
+		if (false === $rows_affected) {
683
+			throw new \RuntimeException(__('Unable to claim actions. Database error.', 'woocommerce'));
684 684
 		}
685 685
 
686 686
 		return (int) $rows_affected;
@@ -695,9 +695,9 @@  discard block
 block discarded – undo
695 695
 		global $wpdb;
696 696
 
697 697
 		$sql = "SELECT COUNT(DISTINCT claim_id) FROM {$wpdb->actionscheduler_actions} WHERE claim_id != 0 AND status IN ( %s, %s)";
698
-		$sql = $wpdb->prepare( $sql, array( self::STATUS_PENDING, self::STATUS_RUNNING ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
698
+		$sql = $wpdb->prepare($sql, array(self::STATUS_PENDING, self::STATUS_RUNNING)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
699 699
 
700
-		return (int) $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
700
+		return (int) $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
701 701
 	}
702 702
 
703 703
 	/**
@@ -706,14 +706,14 @@  discard block
 block discarded – undo
706 706
 	 * @param string $action_id Action ID.
707 707
 	 * @return mixed
708 708
 	 */
709
-	public function get_claim_id( $action_id ) {
709
+	public function get_claim_id($action_id) {
710 710
 		/** @var \wpdb $wpdb */
711 711
 		global $wpdb;
712 712
 
713 713
 		$sql = "SELECT claim_id FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d";
714
-		$sql = $wpdb->prepare( $sql, $action_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
714
+		$sql = $wpdb->prepare($sql, $action_id); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
715 715
 
716
-		return (int) $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
716
+		return (int) $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
717 717
 	}
718 718
 
719 719
 	/**
@@ -722,13 +722,13 @@  discard block
 block discarded – undo
722 722
 	 * @param  int $claim_id Claim ID.
723 723
 	 * @return int[]
724 724
 	 */
725
-	public function find_actions_by_claim_id( $claim_id ) {
725
+	public function find_actions_by_claim_id($claim_id) {
726 726
 		/** @var \wpdb $wpdb */
727 727
 		global $wpdb;
728 728
 
729 729
 		$action_ids  = array();
730
-		$before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object();
731
-		$cut_off     = $before_date->format( 'Y-m-d H:i:s' );
730
+		$before_date = isset($this->claim_before_date) ? $this->claim_before_date : as_get_datetime_object();
731
+		$cut_off     = $before_date->format('Y-m-d H:i:s');
732 732
 
733 733
 		$sql = $wpdb->prepare(
734 734
 			"SELECT action_id, scheduled_date_gmt FROM {$wpdb->actionscheduler_actions} WHERE claim_id = %d",
@@ -737,9 +737,9 @@  discard block
 block discarded – undo
737 737
 
738 738
 		// Verify that the scheduled date for each action is within the expected bounds (in some unusual
739 739
 		// cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify).
740
-		foreach ( $wpdb->get_results( $sql ) as $claimed_action ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
741
-			if ( $claimed_action->scheduled_date_gmt <= $cut_off ) {
742
-				$action_ids[] = absint( $claimed_action->action_id );
740
+		foreach ($wpdb->get_results($sql) as $claimed_action) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
741
+			if ($claimed_action->scheduled_date_gmt <= $cut_off) {
742
+				$action_ids[] = absint($claimed_action->action_id);
743 743
 			}
744 744
 		}
745 745
 
@@ -751,11 +751,11 @@  discard block
 block discarded – undo
751 751
 	 *
752 752
 	 * @param ActionScheduler_ActionClaim $claim Claim object.
753 753
 	 */
754
-	public function release_claim( ActionScheduler_ActionClaim $claim ) {
754
+	public function release_claim(ActionScheduler_ActionClaim $claim) {
755 755
 		/** @var \wpdb $wpdb */
756 756
 		global $wpdb;
757
-		$wpdb->update( $wpdb->actionscheduler_actions, array( 'claim_id' => 0 ), array( 'claim_id' => $claim->get_id() ), array( '%d' ), array( '%d' ) );
758
-		$wpdb->delete( $wpdb->actionscheduler_claims, array( 'claim_id' => $claim->get_id() ), array( '%d' ) );
757
+		$wpdb->update($wpdb->actionscheduler_actions, array('claim_id' => 0), array('claim_id' => $claim->get_id()), array('%d'), array('%d'));
758
+		$wpdb->delete($wpdb->actionscheduler_claims, array('claim_id' => $claim->get_id()), array('%d'));
759 759
 	}
760 760
 
761 761
 	/**
@@ -765,15 +765,15 @@  discard block
 block discarded – undo
765 765
 	 *
766 766
 	 * @return void
767 767
 	 */
768
-	public function unclaim_action( $action_id ) {
768
+	public function unclaim_action($action_id) {
769 769
 		/** @var \wpdb $wpdb */
770 770
 		global $wpdb;
771 771
 		$wpdb->update(
772 772
 			$wpdb->actionscheduler_actions,
773
-			array( 'claim_id' => 0 ),
774
-			array( 'action_id' => $action_id ),
775
-			array( '%s' ),
776
-			array( '%d' )
773
+			array('claim_id' => 0),
774
+			array('action_id' => $action_id),
775
+			array('%s'),
776
+			array('%d')
777 777
 		);
778 778
 	}
779 779
 
@@ -783,18 +783,18 @@  discard block
 block discarded – undo
783 783
 	 * @param int $action_id Action ID.
784 784
 	 * @throws \InvalidArgumentException Throw an exception if action was not updated.
785 785
 	 */
786
-	public function mark_failure( $action_id ) {
786
+	public function mark_failure($action_id) {
787 787
 		/** @var \wpdb $wpdb */
788 788
 		global $wpdb;
789 789
 		$updated = $wpdb->update(
790 790
 			$wpdb->actionscheduler_actions,
791
-			array( 'status' => self::STATUS_FAILED ),
792
-			array( 'action_id' => $action_id ),
793
-			array( '%s' ),
794
-			array( '%d' )
791
+			array('status' => self::STATUS_FAILED),
792
+			array('action_id' => $action_id),
793
+			array('%s'),
794
+			array('%d')
795 795
 		);
796
-		if ( empty( $updated ) ) {
797
-			throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
796
+		if (empty($updated)) {
797
+			throw new \InvalidArgumentException(sprintf(__('Unidentified action %s', 'woocommerce'), $action_id)); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
798 798
 		}
799 799
 	}
800 800
 
@@ -805,13 +805,13 @@  discard block
 block discarded – undo
805 805
 	 *
806 806
 	 * @return void
807 807
 	 */
808
-	public function log_execution( $action_id ) {
808
+	public function log_execution($action_id) {
809 809
 		/** @var \wpdb $wpdb */
810 810
 		global $wpdb;
811 811
 
812 812
 		$sql = "UPDATE {$wpdb->actionscheduler_actions} SET attempts = attempts+1, status=%s, last_attempt_gmt = %s, last_attempt_local = %s WHERE action_id = %d";
813
-		$sql = $wpdb->prepare( $sql, self::STATUS_RUNNING, current_time( 'mysql', true ), current_time( 'mysql' ), $action_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
814
-		$wpdb->query( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
813
+		$sql = $wpdb->prepare($sql, self::STATUS_RUNNING, current_time('mysql', true), current_time('mysql'), $action_id); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
814
+		$wpdb->query($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
815 815
 	}
816 816
 
817 817
 	/**
@@ -822,22 +822,22 @@  discard block
 block discarded – undo
822 822
 	 * @return void
823 823
 	 * @throws \InvalidArgumentException Throw an exception if action was not updated.
824 824
 	 */
825
-	public function mark_complete( $action_id ) {
825
+	public function mark_complete($action_id) {
826 826
 		/** @var \wpdb $wpdb */
827 827
 		global $wpdb;
828 828
 		$updated = $wpdb->update(
829 829
 			$wpdb->actionscheduler_actions,
830 830
 			array(
831 831
 				'status'             => self::STATUS_COMPLETE,
832
-				'last_attempt_gmt'   => current_time( 'mysql', true ),
833
-				'last_attempt_local' => current_time( 'mysql' ),
832
+				'last_attempt_gmt'   => current_time('mysql', true),
833
+				'last_attempt_local' => current_time('mysql'),
834 834
 			),
835
-			array( 'action_id' => $action_id ),
836
-			array( '%s' ),
837
-			array( '%d' )
835
+			array('action_id' => $action_id),
836
+			array('%s'),
837
+			array('%d')
838 838
 		);
839
-		if ( empty( $updated ) ) {
840
-			throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
839
+		if (empty($updated)) {
840
+			throw new \InvalidArgumentException(sprintf(__('Unidentified action %s', 'woocommerce'), $action_id)); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
841 841
 		}
842 842
 
843 843
 		/**
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 		 *
848 848
 		 * @param int $action_id Action ID.
849 849
 		 */
850
-		do_action( 'action_scheduler_completed_action', $action_id );
850
+		do_action('action_scheduler_completed_action', $action_id);
851 851
 	}
852 852
 
853 853
 	/**
@@ -859,17 +859,17 @@  discard block
 block discarded – undo
859 859
 	 * @throws \InvalidArgumentException Throw an exception if not status was found for action_id.
860 860
 	 * @throws \RuntimeException Throw an exception if action status could not be retrieved.
861 861
 	 */
862
-	public function get_status( $action_id ) {
862
+	public function get_status($action_id) {
863 863
 		/** @var \wpdb $wpdb */
864 864
 		global $wpdb;
865 865
 		$sql    = "SELECT status FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d";
866
-		$sql    = $wpdb->prepare( $sql, $action_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
867
-		$status = $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
866
+		$sql    = $wpdb->prepare($sql, $action_id); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
867
+		$status = $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
868 868
 
869
-		if ( null === $status ) {
870
-			throw new \InvalidArgumentException( __( 'Invalid action ID. No status found.', 'woocommerce' ) );
871
-		} elseif ( empty( $status ) ) {
872
-			throw new \RuntimeException( __( 'Unknown status found for action.', 'woocommerce' ) );
869
+		if (null === $status) {
870
+			throw new \InvalidArgumentException(__('Invalid action ID. No status found.', 'woocommerce'));
871
+		} elseif (empty($status)) {
872
+			throw new \RuntimeException(__('Unknown status found for action.', 'woocommerce'));
873 873
 		} else {
874 874
 			return $status;
875 875
 		}
Please login to merge, or discard this patch.
packages/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @return int     The log entry ID.
20 20
 	 */
21
-	public function log( $action_id, $message, DateTime $date = null ) {
22
-		if ( empty( $date ) ) {
21
+	public function log($action_id, $message, DateTime $date = null) {
22
+		if (empty($date)) {
23 23
 			$date = as_get_datetime_object();
24 24
 		} else {
25 25
 			$date = clone $date;
26 26
 		}
27 27
 
28
-		$date_gmt = $date->format( 'Y-m-d H:i:s' );
29
-		ActionScheduler_TimezoneHelper::set_local_timezone( $date );
30
-		$date_local = $date->format( 'Y-m-d H:i:s' );
28
+		$date_gmt = $date->format('Y-m-d H:i:s');
29
+		ActionScheduler_TimezoneHelper::set_local_timezone($date);
30
+		$date_local = $date->format('Y-m-d H:i:s');
31 31
 
32 32
 		/** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort
33 33
 		global $wpdb;
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 				'log_date_gmt'   => $date_gmt,
40 40
 				'log_date_local' => $date_local,
41 41
 			),
42
-			array( '%d', '%s', '%s', '%s' )
42
+			array('%d', '%s', '%s', '%s')
43 43
 		);
44 44
 
45 45
 		return $wpdb->insert_id;
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @return ActionScheduler_LogEntry
54 54
 	 */
55
-	public function get_entry( $entry_id ) {
55
+	public function get_entry($entry_id) {
56 56
 		/** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort
57 57
 		global $wpdb;
58
-		$entry = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE log_id=%d", $entry_id ) );
58
+		$entry = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->actionscheduler_logs} WHERE log_id=%d", $entry_id));
59 59
 
60
-		return $this->create_entry_from_db_record( $entry );
60
+		return $this->create_entry_from_db_record($entry);
61 61
 	}
62 62
 
63 63
 	/**
@@ -67,18 +67,18 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @return ActionScheduler_LogEntry
69 69
 	 */
70
-	private function create_entry_from_db_record( $record ) {
71
-		if ( empty( $record ) ) {
70
+	private function create_entry_from_db_record($record) {
71
+		if (empty($record)) {
72 72
 			return new ActionScheduler_NullLogEntry();
73 73
 		}
74 74
 
75
-		if ( is_null( $record->log_date_gmt ) ) {
76
-			$date = as_get_datetime_object( ActionScheduler_StoreSchema::DEFAULT_DATE );
75
+		if (is_null($record->log_date_gmt)) {
76
+			$date = as_get_datetime_object(ActionScheduler_StoreSchema::DEFAULT_DATE);
77 77
 		} else {
78
-			$date = as_get_datetime_object( $record->log_date_gmt );
78
+			$date = as_get_datetime_object($record->log_date_gmt);
79 79
 		}
80 80
 
81
-		return new ActionScheduler_LogEntry( $record->action_id, $record->message, $date );
81
+		return new ActionScheduler_LogEntry($record->action_id, $record->message, $date);
82 82
 	}
83 83
 
84 84
 	/**
@@ -88,13 +88,13 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @return ActionScheduler_LogEntry[]
90 90
 	 */
91
-	public function get_logs( $action_id ) {
91
+	public function get_logs($action_id) {
92 92
 		/** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort
93 93
 		global $wpdb;
94 94
 
95
-		$records = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE action_id=%d", $action_id ) );
95
+		$records = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->actionscheduler_logs} WHERE action_id=%d", $action_id));
96 96
 
97
-		return array_map( array( $this, 'create_entry_from_db_record' ), $records );
97
+		return array_map(array($this, 'create_entry_from_db_record'), $records);
98 98
 	}
99 99
 
100 100
 	/**
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 
110 110
 		parent::init();
111 111
 
112
-		add_action( 'action_scheduler_deleted_action', array( $this, 'clear_deleted_action_logs' ), 10, 1 );
112
+		add_action('action_scheduler_deleted_action', array($this, 'clear_deleted_action_logs'), 10, 1);
113 113
 	}
114 114
 
115 115
 	/**
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param int $action_id Action ID.
119 119
 	 */
120
-	public function clear_deleted_action_logs( $action_id ) {
120
+	public function clear_deleted_action_logs($action_id) {
121 121
 		/** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort
122 122
 		global $wpdb;
123
-		$wpdb->delete( $wpdb->actionscheduler_logs, array( 'action_id' => $action_id ), array( '%d' ) );
123
+		$wpdb->delete($wpdb->actionscheduler_logs, array('action_id' => $action_id), array('%d'));
124 124
 	}
125 125
 
126 126
 	/**
@@ -128,27 +128,27 @@  discard block
 block discarded – undo
128 128
 	 *
129 129
 	 * @param array $action_ids List of action ID.
130 130
 	 */
131
-	public function bulk_log_cancel_actions( $action_ids ) {
132
-		if ( empty( $action_ids ) ) {
131
+	public function bulk_log_cancel_actions($action_ids) {
132
+		if (empty($action_ids)) {
133 133
 			return;
134 134
 		}
135 135
 
136 136
 		/** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort
137 137
 		global $wpdb;
138 138
 		$date     = as_get_datetime_object();
139
-		$date_gmt = $date->format( 'Y-m-d H:i:s' );
140
-		ActionScheduler_TimezoneHelper::set_local_timezone( $date );
141
-		$date_local = $date->format( 'Y-m-d H:i:s' );
142
-		$message    = __( 'action canceled', 'woocommerce' );
143
-		$format     = '(%d, ' . $wpdb->prepare( '%s, %s, %s', $message, $date_gmt, $date_local ) . ')';
139
+		$date_gmt = $date->format('Y-m-d H:i:s');
140
+		ActionScheduler_TimezoneHelper::set_local_timezone($date);
141
+		$date_local = $date->format('Y-m-d H:i:s');
142
+		$message    = __('action canceled', 'woocommerce');
143
+		$format     = '(%d, ' . $wpdb->prepare('%s, %s, %s', $message, $date_gmt, $date_local) . ')';
144 144
 		$sql_query  = "INSERT {$wpdb->actionscheduler_logs} (action_id, message, log_date_gmt, log_date_local) VALUES ";
145 145
 		$value_rows = array();
146 146
 
147
-		foreach ( $action_ids as $action_id ) {
148
-			$value_rows[] = $wpdb->prepare( $format, $action_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
147
+		foreach ($action_ids as $action_id) {
148
+			$value_rows[] = $wpdb->prepare($format, $action_id); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
149 149
 		}
150
-		$sql_query .= implode( ',', $value_rows );
150
+		$sql_query .= implode(',', $value_rows);
151 151
 
152
-		$wpdb->query( $sql_query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
152
+		$wpdb->query($sql_query); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
153 153
 	}
154 154
 }
Please login to merge, or discard this patch.
classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,12 +6,12 @@  discard block
 block discarded – undo
6 6
  */
7 7
 class ActionScheduler_wpPostStore_TaxonomyRegistrar {
8 8
 	public function register() {
9
-		register_taxonomy( ActionScheduler_wpPostStore::GROUP_TAXONOMY, ActionScheduler_wpPostStore::POST_TYPE, $this->taxonomy_args() );
9
+		register_taxonomy(ActionScheduler_wpPostStore::GROUP_TAXONOMY, ActionScheduler_wpPostStore::POST_TYPE, $this->taxonomy_args());
10 10
 	}
11 11
 
12 12
 	protected function taxonomy_args() {
13 13
 		$args = array(
14
-			'label' => __( 'Action Group', 'woocommerce' ),
14
+			'label' => __('Action Group', 'woocommerce'),
15 15
 			'public' => false,
16 16
 			'hierarchical' => false,
17 17
 			'show_admin_column' => true,
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 			'rewrite' => false,
20 20
 		);
21 21
 
22
-		$args = apply_filters( 'action_scheduler_taxonomy_args', $args );
22
+		$args = apply_filters('action_scheduler_taxonomy_args', $args);
23 23
 		return $args;
24 24
 	}
25 25
 }
Please login to merge, or discard this patch.
action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php 1 patch
Spacing   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -35,18 +35,18 @@  discard block
 block discarded – undo
35 35
 	 * @throws RuntimeException Throws an exception if the action could not be saved.
36 36
 	 * @return int
37 37
 	 */
38
-	public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = null ) {
38
+	public function save_action(ActionScheduler_Action $action, DateTime $scheduled_date = null) {
39 39
 		try {
40
-			$this->validate_action( $action );
41
-			$post_array = $this->create_post_array( $action, $scheduled_date );
42
-			$post_id    = $this->save_post_array( $post_array );
43
-			$this->save_post_schedule( $post_id, $action->get_schedule() );
44
-			$this->save_action_group( $post_id, $action->get_group() );
45
-			do_action( 'action_scheduler_stored_action', $post_id );
40
+			$this->validate_action($action);
41
+			$post_array = $this->create_post_array($action, $scheduled_date);
42
+			$post_id    = $this->save_post_array($post_array);
43
+			$this->save_post_schedule($post_id, $action->get_schedule());
44
+			$this->save_action_group($post_id, $action->get_group());
45
+			do_action('action_scheduler_stored_action', $post_id);
46 46
 			return $post_id;
47
-		} catch ( Exception $e ) {
47
+		} catch (Exception $e) {
48 48
 			/* translators: %s: action error message */
49
-			throw new RuntimeException( sprintf( __( 'Error saving action: %s', 'woocommerce' ), $e->getMessage() ), 0 );
49
+			throw new RuntimeException(sprintf(__('Error saving action: %s', 'woocommerce'), $e->getMessage()), 0);
50 50
 		}
51 51
 	}
52 52
 
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @return array Returns an array of post data.
60 60
 	 */
61
-	protected function create_post_array( ActionScheduler_Action $action, DateTime $scheduled_date = null ) {
61
+	protected function create_post_array(ActionScheduler_Action $action, DateTime $scheduled_date = null) {
62 62
 		$post = array(
63 63
 			'post_type'     => self::POST_TYPE,
64 64
 			'post_title'    => $action->get_hook(),
65
-			'post_content'  => wp_json_encode( $action->get_args() ),
66
-			'post_status'   => ( $action->is_finished() ? 'publish' : 'pending' ),
67
-			'post_date_gmt' => $this->get_scheduled_date_string( $action, $scheduled_date ),
68
-			'post_date'     => $this->get_scheduled_date_string_local( $action, $scheduled_date ),
65
+			'post_content'  => wp_json_encode($action->get_args()),
66
+			'post_status'   => ($action->is_finished() ? 'publish' : 'pending'),
67
+			'post_date_gmt' => $this->get_scheduled_date_string($action, $scheduled_date),
68
+			'post_date'     => $this->get_scheduled_date_string_local($action, $scheduled_date),
69 69
 		);
70 70
 		return $post;
71 71
 	}
@@ -77,28 +77,28 @@  discard block
 block discarded – undo
77 77
 	 * @return int Returns the post ID.
78 78
 	 * @throws RuntimeException Throws an exception if the action could not be saved.
79 79
 	 */
80
-	protected function save_post_array( $post_array ) {
81
-		add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 );
82
-		add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 );
80
+	protected function save_post_array($post_array) {
81
+		add_filter('wp_insert_post_data', array($this, 'filter_insert_post_data'), 10, 1);
82
+		add_filter('pre_wp_unique_post_slug', array($this, 'set_unique_post_slug'), 10, 5);
83 83
 
84
-		$has_kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' );
84
+		$has_kses = false !== has_filter('content_save_pre', 'wp_filter_post_kses');
85 85
 
86
-		if ( $has_kses ) {
86
+		if ($has_kses) {
87 87
 			// Prevent KSES from corrupting JSON in post_content.
88 88
 			kses_remove_filters();
89 89
 		}
90 90
 
91
-		$post_id = wp_insert_post( $post_array );
91
+		$post_id = wp_insert_post($post_array);
92 92
 
93
-		if ( $has_kses ) {
93
+		if ($has_kses) {
94 94
 			kses_init_filters();
95 95
 		}
96 96
 
97
-		remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 );
98
-		remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 );
97
+		remove_filter('wp_insert_post_data', array($this, 'filter_insert_post_data'), 10);
98
+		remove_filter('pre_wp_unique_post_slug', array($this, 'set_unique_post_slug'), 10);
99 99
 
100
-		if ( is_wp_error( $post_id ) || empty( $post_id ) ) {
101
-			throw new RuntimeException( __( 'Unable to save action.', 'woocommerce' ) );
100
+		if (is_wp_error($post_id) || empty($post_id)) {
101
+			throw new RuntimeException(__('Unable to save action.', 'woocommerce'));
102 102
 		}
103 103
 		return $post_id;
104 104
 	}
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
 	 *
111 111
 	 * @return array
112 112
 	 */
113
-	public function filter_insert_post_data( $postdata ) {
114
-		if ( self::POST_TYPE === $postdata['post_type'] ) {
113
+	public function filter_insert_post_data($postdata) {
114
+		if (self::POST_TYPE === $postdata['post_type']) {
115 115
 			$postdata['post_author'] = 0;
116
-			if ( 'future' === $postdata['post_status'] ) {
116
+			if ('future' === $postdata['post_status']) {
117 117
 				$postdata['post_status'] = 'publish';
118 118
 			}
119 119
 		}
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 	 * @param string $post_type     Post type.
149 149
 	 * @return string
150 150
 	 */
151
-	public function set_unique_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type ) {
152
-		if ( self::POST_TYPE === $post_type ) {
153
-			$override_slug = uniqid( self::POST_TYPE . '-', true ) . '-' . wp_generate_password( 32, false );
151
+	public function set_unique_post_slug($override_slug, $slug, $post_ID, $post_status, $post_type) {
152
+		if (self::POST_TYPE === $post_type) {
153
+			$override_slug = uniqid(self::POST_TYPE . '-', true) . '-' . wp_generate_password(32, false);
154 154
 		}
155 155
 		return $override_slug;
156 156
 	}
@@ -163,8 +163,8 @@  discard block
 block discarded – undo
163 163
 	 *
164 164
 	 * @return void
165 165
 	 */
166
-	protected function save_post_schedule( $post_id, $schedule ) {
167
-		update_post_meta( $post_id, self::SCHEDULE_META_KEY, $schedule );
166
+	protected function save_post_schedule($post_id, $schedule) {
167
+		update_post_meta($post_id, self::SCHEDULE_META_KEY, $schedule);
168 168
 	}
169 169
 
170 170
 	/**
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 	 * @param string $group   Group to save.
175 175
 	 * @return void
176 176
 	 */
177
-	protected function save_action_group( $post_id, $group ) {
178
-		if ( empty( $group ) ) {
179
-			wp_set_object_terms( $post_id, array(), self::GROUP_TAXONOMY, false );
177
+	protected function save_action_group($post_id, $group) {
178
+		if (empty($group)) {
179
+			wp_set_object_terms($post_id, array(), self::GROUP_TAXONOMY, false);
180 180
 		} else {
181
-			wp_set_object_terms( $post_id, array( $group ), self::GROUP_TAXONOMY, false );
181
+			wp_set_object_terms($post_id, array($group), self::GROUP_TAXONOMY, false);
182 182
 		}
183 183
 	}
184 184
 
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 	 * @param int $action_id Action ID.
189 189
 	 * @return object
190 190
 	 */
191
-	public function fetch_action( $action_id ) {
192
-		$post = $this->get_post( $action_id );
193
-		if ( empty( $post ) || self::POST_TYPE !== $post->post_type ) {
191
+	public function fetch_action($action_id) {
192
+		$post = $this->get_post($action_id);
193
+		if (empty($post) || self::POST_TYPE !== $post->post_type) {
194 194
 			return $this->get_null_action();
195 195
 		}
196 196
 
197 197
 		try {
198
-			$action = $this->make_action_from_post( $post );
199
-		} catch ( ActionScheduler_InvalidActionException $exception ) {
200
-			do_action( 'action_scheduler_failed_fetch_action', $post->ID, $exception );
198
+			$action = $this->make_action_from_post($post);
199
+		} catch (ActionScheduler_InvalidActionException $exception) {
200
+			do_action('action_scheduler_failed_fetch_action', $post->ID, $exception);
201 201
 			return $this->get_null_action();
202 202
 		}
203 203
 
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
 	 * @param string $action_id - Action ID.
211 211
 	 * @return WP_Post|null
212 212
 	 */
213
-	protected function get_post( $action_id ) {
214
-		if ( empty( $action_id ) ) {
213
+	protected function get_post($action_id) {
214
+		if (empty($action_id)) {
215 215
 			return null;
216 216
 		}
217
-		return get_post( $action_id );
217
+		return get_post($action_id);
218 218
 	}
219 219
 
220 220
 	/**
@@ -232,19 +232,19 @@  discard block
 block discarded – undo
232 232
 	 * @param WP_Post $post Post object.
233 233
 	 * @return WP_Post
234 234
 	 */
235
-	protected function make_action_from_post( $post ) {
235
+	protected function make_action_from_post($post) {
236 236
 		$hook = $post->post_title;
237 237
 
238
-		$args = json_decode( $post->post_content, true );
239
-		$this->validate_args( $args, $post->ID );
238
+		$args = json_decode($post->post_content, true);
239
+		$this->validate_args($args, $post->ID);
240 240
 
241
-		$schedule = get_post_meta( $post->ID, self::SCHEDULE_META_KEY, true );
242
-		$this->validate_schedule( $schedule, $post->ID );
241
+		$schedule = get_post_meta($post->ID, self::SCHEDULE_META_KEY, true);
242
+		$this->validate_schedule($schedule, $post->ID);
243 243
 
244
-		$group = wp_get_object_terms( $post->ID, self::GROUP_TAXONOMY, array( 'fields' => 'names' ) );
245
-		$group = empty( $group ) ? '' : reset( $group );
244
+		$group = wp_get_object_terms($post->ID, self::GROUP_TAXONOMY, array('fields' => 'names'));
245
+		$group = empty($group) ? '' : reset($group);
246 246
 
247
-		return ActionScheduler::factory()->get_stored_action( $this->get_action_status_by_post_status( $post->post_status ), $hook, $args, $schedule, $group );
247
+		return ActionScheduler::factory()->get_stored_action($this->get_action_status_by_post_status($post->post_status), $hook, $args, $schedule, $group);
248 248
 	}
249 249
 
250 250
 	/**
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 	 * @throws InvalidArgumentException Throw InvalidArgumentException if $post_status not in known status fields returned by $this->get_status_labels().
256 256
 	 * @return string
257 257
 	 */
258
-	protected function get_action_status_by_post_status( $post_status ) {
258
+	protected function get_action_status_by_post_status($post_status) {
259 259
 
260
-		switch ( $post_status ) {
260
+		switch ($post_status) {
261 261
 			case 'publish':
262 262
 				$action_status = self::STATUS_COMPLETE;
263 263
 				break;
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
 				$action_status = self::STATUS_CANCELED;
266 266
 				break;
267 267
 			default:
268
-				if ( ! array_key_exists( $post_status, $this->get_status_labels() ) ) {
269
-					throw new InvalidArgumentException( sprintf( 'Invalid post status: "%s". No matching action status available.', $post_status ) );
268
+				if (!array_key_exists($post_status, $this->get_status_labels())) {
269
+					throw new InvalidArgumentException(sprintf('Invalid post status: "%s". No matching action status available.', $post_status));
270 270
 				}
271 271
 				$action_status = $post_status;
272 272
 				break;
@@ -283,9 +283,9 @@  discard block
 block discarded – undo
283 283
 	 * @throws InvalidArgumentException Throws InvalidArgumentException if $post_status not in known status fields returned by $this->get_status_labels().
284 284
 	 * @return string
285 285
 	 */
286
-	protected function get_post_status_by_action_status( $action_status ) {
286
+	protected function get_post_status_by_action_status($action_status) {
287 287
 
288
-		switch ( $action_status ) {
288
+		switch ($action_status) {
289 289
 			case self::STATUS_COMPLETE:
290 290
 				$post_status = 'publish';
291 291
 				break;
@@ -293,8 +293,8 @@  discard block
 block discarded – undo
293 293
 				$post_status = 'trash';
294 294
 				break;
295 295
 			default:
296
-				if ( ! array_key_exists( $action_status, $this->get_status_labels() ) ) {
297
-					throw new InvalidArgumentException( sprintf( 'Invalid action status: "%s".', $action_status ) );
296
+				if (!array_key_exists($action_status, $this->get_status_labels())) {
297
+					throw new InvalidArgumentException(sprintf('Invalid action status: "%s".', $action_status));
298 298
 				}
299 299
 				$post_status = $action_status;
300 300
 				break;
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
 	 * @throws InvalidArgumentException - Throw InvalidArgumentException if $select_or_count not count or select.
313 313
 	 * @return string SQL statement. The returned SQL is already properly escaped.
314 314
 	 */
315
-	protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) {
315
+	protected function get_query_actions_sql(array $query, $select_or_count = 'select') {
316 316
 
317
-		if ( ! in_array( $select_or_count, array( 'select', 'count' ), true ) ) {
318
-			throw new InvalidArgumentException( __( 'Invalid schedule. Cannot save action.', 'woocommerce' ) );
317
+		if (!in_array($select_or_count, array('select', 'count'), true)) {
318
+			throw new InvalidArgumentException(__('Invalid schedule. Cannot save action.', 'woocommerce'));
319 319
 		}
320 320
 
321 321
 		$query = wp_parse_args(
@@ -344,14 +344,14 @@  discard block
 block discarded – undo
344 344
 		 * @var wpdb $wpdb
345 345
 		 */
346 346
 		global $wpdb;
347
-		$sql        = ( 'count' === $select_or_count ) ? 'SELECT count(p.ID)' : 'SELECT p.ID ';
347
+		$sql        = ('count' === $select_or_count) ? 'SELECT count(p.ID)' : 'SELECT p.ID ';
348 348
 		$sql       .= "FROM {$wpdb->posts} p";
349 349
 		$sql_params = array();
350
-		if ( empty( $query['group'] ) && 'group' === $query['orderby'] ) {
350
+		if (empty($query['group']) && 'group' === $query['orderby']) {
351 351
 			$sql .= " LEFT JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID";
352 352
 			$sql .= " LEFT JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id";
353 353
 			$sql .= " LEFT JOIN {$wpdb->terms} t ON tt.term_id=t.term_id";
354
-		} elseif ( ! empty( $query['group'] ) ) {
354
+		} elseif (!empty($query['group'])) {
355 355
 			$sql         .= " INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID";
356 356
 			$sql         .= " INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id";
357 357
 			$sql         .= " INNER JOIN {$wpdb->terms} t ON tt.term_id=t.term_id";
@@ -360,58 +360,58 @@  discard block
 block discarded – undo
360 360
 		}
361 361
 		$sql         .= ' WHERE post_type=%s';
362 362
 		$sql_params[] = self::POST_TYPE;
363
-		if ( $query['hook'] ) {
363
+		if ($query['hook']) {
364 364
 			$sql         .= ' AND p.post_title=%s';
365 365
 			$sql_params[] = $query['hook'];
366 366
 		}
367
-		if ( ! is_null( $query['args'] ) ) {
367
+		if (!is_null($query['args'])) {
368 368
 			$sql         .= ' AND p.post_content=%s';
369
-			$sql_params[] = wp_json_encode( $query['args'] );
369
+			$sql_params[] = wp_json_encode($query['args']);
370 370
 		}
371 371
 
372
-		if ( $query['status'] ) {
373
-			$post_statuses = array_map( array( $this, 'get_post_status_by_action_status' ), (array) $query['status'] );
374
-			$placeholders  = array_fill( 0, count( $post_statuses ), '%s' );
375
-			$sql          .= ' AND p.post_status IN (' . join( ', ', $placeholders ) . ')';
376
-			$sql_params    = array_merge( $sql_params, array_values( $post_statuses ) );
372
+		if ($query['status']) {
373
+			$post_statuses = array_map(array($this, 'get_post_status_by_action_status'), (array) $query['status']);
374
+			$placeholders  = array_fill(0, count($post_statuses), '%s');
375
+			$sql          .= ' AND p.post_status IN (' . join(', ', $placeholders) . ')';
376
+			$sql_params    = array_merge($sql_params, array_values($post_statuses));
377 377
 		}
378 378
 
379
-		if ( $query['date'] instanceof DateTime ) {
379
+		if ($query['date'] instanceof DateTime) {
380 380
 			$date = clone $query['date'];
381
-			$date->setTimezone( new DateTimeZone( 'UTC' ) );
382
-			$date_string  = $date->format( 'Y-m-d H:i:s' );
383
-			$comparator   = $this->validate_sql_comparator( $query['date_compare'] );
381
+			$date->setTimezone(new DateTimeZone('UTC'));
382
+			$date_string  = $date->format('Y-m-d H:i:s');
383
+			$comparator   = $this->validate_sql_comparator($query['date_compare']);
384 384
 			$sql         .= " AND p.post_date_gmt $comparator %s";
385 385
 			$sql_params[] = $date_string;
386 386
 		}
387 387
 
388
-		if ( $query['modified'] instanceof DateTime ) {
388
+		if ($query['modified'] instanceof DateTime) {
389 389
 			$modified = clone $query['modified'];
390
-			$modified->setTimezone( new DateTimeZone( 'UTC' ) );
391
-			$date_string  = $modified->format( 'Y-m-d H:i:s' );
392
-			$comparator   = $this->validate_sql_comparator( $query['modified_compare'] );
390
+			$modified->setTimezone(new DateTimeZone('UTC'));
391
+			$date_string  = $modified->format('Y-m-d H:i:s');
392
+			$comparator   = $this->validate_sql_comparator($query['modified_compare']);
393 393
 			$sql         .= " AND p.post_modified_gmt $comparator %s";
394 394
 			$sql_params[] = $date_string;
395 395
 		}
396 396
 
397
-		if ( true === $query['claimed'] ) {
397
+		if (true === $query['claimed']) {
398 398
 			$sql .= " AND p.post_password != ''";
399
-		} elseif ( false === $query['claimed'] ) {
399
+		} elseif (false === $query['claimed']) {
400 400
 			$sql .= " AND p.post_password = ''";
401
-		} elseif ( ! is_null( $query['claimed'] ) ) {
401
+		} elseif (!is_null($query['claimed'])) {
402 402
 			$sql         .= ' AND p.post_password = %s';
403 403
 			$sql_params[] = $query['claimed'];
404 404
 		}
405 405
 
406
-		if ( ! empty( $query['search'] ) ) {
406
+		if (!empty($query['search'])) {
407 407
 			$sql .= ' AND (p.post_title LIKE %s OR p.post_content LIKE %s OR p.post_password LIKE %s)';
408
-			for ( $i = 0; $i < 3; $i++ ) {
409
-				$sql_params[] = sprintf( '%%%s%%', $query['search'] );
408
+			for ($i = 0; $i < 3; $i++) {
409
+				$sql_params[] = sprintf('%%%s%%', $query['search']);
410 410
 			}
411 411
 		}
412 412
 
413
-		if ( 'select' === $select_or_count ) {
414
-			switch ( $query['orderby'] ) {
413
+		if ('select' === $select_or_count) {
414
+			switch ($query['orderby']) {
415 415
 				case 'hook':
416 416
 					$orderby = 'p.post_title';
417 417
 					break;
@@ -433,20 +433,20 @@  discard block
 block discarded – undo
433 433
 					$orderby = 'p.post_date_gmt';
434 434
 					break;
435 435
 			}
436
-			if ( 'ASC' === strtoupper( $query['order'] ) ) {
436
+			if ('ASC' === strtoupper($query['order'])) {
437 437
 				$order = 'ASC';
438 438
 			} else {
439 439
 				$order = 'DESC';
440 440
 			}
441 441
 			$sql .= " ORDER BY $orderby $order";
442
-			if ( $query['per_page'] > 0 ) {
442
+			if ($query['per_page'] > 0) {
443 443
 				$sql         .= ' LIMIT %d, %d';
444 444
 				$sql_params[] = $query['offset'];
445 445
 				$sql_params[] = $query['per_page'];
446 446
 			}
447 447
 		}
448 448
 
449
-		return $wpdb->prepare( $sql, $sql_params ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
449
+		return $wpdb->prepare($sql, $sql_params); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
450 450
 	}
451 451
 
452 452
 	/**
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	 *
462 462
 	 * @return string|array|null The IDs of actions matching the query. Null on failure.
463 463
 	 */
464
-	public function query_actions( $query = array(), $query_type = 'select' ) {
464
+	public function query_actions($query = array(), $query_type = 'select') {
465 465
 		/**
466 466
 		 * Global $wpdb object.
467 467
 		 *
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
 		 */
470 470
 		global $wpdb;
471 471
 
472
-		$sql = $this->get_query_actions_sql( $query, $query_type );
472
+		$sql = $this->get_query_actions_sql($query, $query_type);
473 473
 
474
-		return ( 'count' === $query_type ) ? $wpdb->get_var( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared
474
+		return ('count' === $query_type) ? $wpdb->get_var($sql) : $wpdb->get_col($sql); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared
475 475
 	}
476 476
 
477 477
 	/**
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
 
484 484
 		$action_counts_by_status = array();
485 485
 		$action_stati_and_labels = $this->get_status_labels();
486
-		$posts_count_by_status   = (array) wp_count_posts( self::POST_TYPE, 'readable' );
486
+		$posts_count_by_status   = (array) wp_count_posts(self::POST_TYPE, 'readable');
487 487
 
488
-		foreach ( $posts_count_by_status as $post_status_name => $count ) {
488
+		foreach ($posts_count_by_status as $post_status_name => $count) {
489 489
 
490 490
 			try {
491
-				$action_status_name = $this->get_action_status_by_post_status( $post_status_name );
492
-			} catch ( Exception $e ) {
491
+				$action_status_name = $this->get_action_status_by_post_status($post_status_name);
492
+			} catch (Exception $e) {
493 493
 				// Ignore any post statuses that aren't for actions.
494 494
 				continue;
495 495
 			}
496
-			if ( array_key_exists( $action_status_name, $action_stati_and_labels ) ) {
497
-				$action_counts_by_status[ $action_status_name ] = $count;
496
+			if (array_key_exists($action_status_name, $action_stati_and_labels)) {
497
+				$action_counts_by_status[$action_status_name] = $count;
498 498
 			}
499 499
 		}
500 500
 
@@ -508,16 +508,16 @@  discard block
 block discarded – undo
508 508
 	 *
509 509
 	 * @throws InvalidArgumentException If $action_id is not identified.
510 510
 	 */
511
-	public function cancel_action( $action_id ) {
512
-		$post = get_post( $action_id );
513
-		if ( empty( $post ) || ( self::POST_TYPE !== $post->post_type ) ) {
511
+	public function cancel_action($action_id) {
512
+		$post = get_post($action_id);
513
+		if (empty($post) || (self::POST_TYPE !== $post->post_type)) {
514 514
 			/* translators: %s is the action ID */
515
-			throw new InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) );
515
+			throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'woocommerce'), $action_id));
516 516
 		}
517
-		do_action( 'action_scheduler_canceled_action', $action_id );
518
-		add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 );
519
-		wp_trash_post( $action_id );
520
-		remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 );
517
+		do_action('action_scheduler_canceled_action', $action_id);
518
+		add_filter('pre_wp_unique_post_slug', array($this, 'set_unique_post_slug'), 10, 5);
519
+		wp_trash_post($action_id);
520
+		remove_filter('pre_wp_unique_post_slug', array($this, 'set_unique_post_slug'), 10);
521 521
 	}
522 522
 
523 523
 	/**
@@ -527,15 +527,15 @@  discard block
 block discarded – undo
527 527
 	 * @return void
528 528
 	 * @throws InvalidArgumentException If action is not identified.
529 529
 	 */
530
-	public function delete_action( $action_id ) {
531
-		$post = get_post( $action_id );
532
-		if ( empty( $post ) || ( self::POST_TYPE !== $post->post_type ) ) {
530
+	public function delete_action($action_id) {
531
+		$post = get_post($action_id);
532
+		if (empty($post) || (self::POST_TYPE !== $post->post_type)) {
533 533
 			/* translators: %s is the action ID */
534
-			throw new InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) );
534
+			throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'woocommerce'), $action_id));
535 535
 		}
536
-		do_action( 'action_scheduler_deleted_action', $action_id );
536
+		do_action('action_scheduler_deleted_action', $action_id);
537 537
 
538
-		wp_delete_post( $action_id, true );
538
+		wp_delete_post($action_id, true);
539 539
 	}
540 540
 
541 541
 	/**
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
 	 * @param int $action_id Action ID.
545 545
 	 * @return ActionScheduler_DateTime The date the action is schedule to run, or the date that it ran.
546 546
 	 */
547
-	public function get_date( $action_id ) {
548
-		$next = $this->get_date_gmt( $action_id );
549
-		return ActionScheduler_TimezoneHelper::set_local_timezone( $next );
547
+	public function get_date($action_id) {
548
+		$next = $this->get_date_gmt($action_id);
549
+		return ActionScheduler_TimezoneHelper::set_local_timezone($next);
550 550
 	}
551 551
 
552 552
 	/**
@@ -557,16 +557,16 @@  discard block
 block discarded – undo
557 557
 	 * @throws InvalidArgumentException If $action_id is not identified.
558 558
 	 * @return ActionScheduler_DateTime The date the action is schedule to run, or the date that it ran.
559 559
 	 */
560
-	public function get_date_gmt( $action_id ) {
561
-		$post = get_post( $action_id );
562
-		if ( empty( $post ) || ( self::POST_TYPE !== $post->post_type ) ) {
560
+	public function get_date_gmt($action_id) {
561
+		$post = get_post($action_id);
562
+		if (empty($post) || (self::POST_TYPE !== $post->post_type)) {
563 563
 			/* translators: %s is the action ID */
564
-			throw new InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) );
564
+			throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'woocommerce'), $action_id));
565 565
 		}
566
-		if ( 'publish' === $post->post_status ) {
567
-			return as_get_datetime_object( $post->post_modified_gmt );
566
+		if ('publish' === $post->post_status) {
567
+			return as_get_datetime_object($post->post_modified_gmt);
568 568
 		} else {
569
-			return as_get_datetime_object( $post->post_date_gmt );
569
+			return as_get_datetime_object($post->post_date_gmt);
570 570
 		}
571 571
 	}
572 572
 
@@ -582,14 +582,14 @@  discard block
 block discarded – undo
582 582
 	 * @throws RuntimeException When there is an error staking a claim.
583 583
 	 * @throws InvalidArgumentException When the given group is not valid.
584 584
 	 */
585
-	public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) {
585
+	public function stake_claim($max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '') {
586 586
 		$this->claim_before_date = $before_date;
587 587
 		$claim_id                = $this->generate_claim_id();
588
-		$this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group );
589
-		$action_ids              = $this->find_actions_by_claim_id( $claim_id );
588
+		$this->claim_actions($claim_id, $max_actions, $before_date, $hooks, $group);
589
+		$action_ids              = $this->find_actions_by_claim_id($claim_id);
590 590
 		$this->claim_before_date = null;
591 591
 
592
-		return new ActionScheduler_ActionClaim( $claim_id, $action_ids );
592
+		return new ActionScheduler_ActionClaim($claim_id, $action_ids);
593 593
 	}
594 594
 
595 595
 	/**
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
 		return $wpdb->get_var(
605 605
 			$wpdb->prepare(
606 606
 				"SELECT COUNT(DISTINCT post_password) FROM {$wpdb->posts} WHERE post_password != '' AND post_type = %s AND post_status IN ('in-progress','pending')",
607
-				array( self::POST_TYPE )
607
+				array(self::POST_TYPE)
608 608
 			)
609 609
 		);
610 610
 	}
@@ -615,8 +615,8 @@  discard block
 block discarded – undo
615 615
 	 * @return string
616 616
 	 */
617 617
 	protected function generate_claim_id() {
618
-		$claim_id = md5( microtime( true ) . wp_rand( 0, 1000 ) );
619
-		return substr( $claim_id, 0, 20 ); // to fit in db field with 20 char limit.
618
+		$claim_id = md5(microtime(true) . wp_rand(0, 1000));
619
+		return substr($claim_id, 0, 20); // to fit in db field with 20 char limit.
620 620
 	}
621 621
 
622 622
 	/**
@@ -631,14 +631,14 @@  discard block
 block discarded – undo
631 631
 	 * @return int The number of actions that were claimed.
632 632
 	 * @throws RuntimeException  When there is a database error.
633 633
 	 */
634
-	protected function claim_actions( $claim_id, $limit, DateTime $before_date = null, $hooks = array(), $group = '' ) {
634
+	protected function claim_actions($claim_id, $limit, DateTime $before_date = null, $hooks = array(), $group = '') {
635 635
 		// Set up initial variables.
636 636
 		$date      = null === $before_date ? as_get_datetime_object() : clone $before_date;
637
-		$limit_ids = ! empty( $group );
638
-		$ids       = $limit_ids ? $this->get_actions_by_group( $group, $limit, $date ) : array();
637
+		$limit_ids = !empty($group);
638
+		$ids       = $limit_ids ? $this->get_actions_by_group($group, $limit, $date) : array();
639 639
 
640 640
 		// If limiting by IDs and no posts found, then return early since we have nothing to update.
641
-		if ( $limit_ids && 0 === count( $ids ) ) {
641
+		if ($limit_ids && 0 === count($ids)) {
642 642
 			return 0;
643 643
 		}
644 644
 
@@ -658,8 +658,8 @@  discard block
 block discarded – undo
658 658
 		$update = "UPDATE {$wpdb->posts} SET post_password = %s, post_modified_gmt = %s, post_modified = %s";
659 659
 		$params = array(
660 660
 			$claim_id,
661
-			current_time( 'mysql', true ),
662
-			current_time( 'mysql' ),
661
+			current_time('mysql', true),
662
+			current_time('mysql'),
663 663
 		);
664 664
 
665 665
 		// Build initial WHERE clause.
@@ -667,10 +667,10 @@  discard block
 block discarded – undo
667 667
 		$params[] = self::POST_TYPE;
668 668
 		$params[] = ActionScheduler_Store::STATUS_PENDING;
669 669
 
670
-		if ( ! empty( $hooks ) ) {
671
-			$placeholders = array_fill( 0, count( $hooks ), '%s' );
672
-			$where       .= ' AND post_title IN (' . join( ', ', $placeholders ) . ')';
673
-			$params       = array_merge( $params, array_values( $hooks ) );
670
+		if (!empty($hooks)) {
671
+			$placeholders = array_fill(0, count($hooks), '%s');
672
+			$where       .= ' AND post_title IN (' . join(', ', $placeholders) . ')';
673
+			$params       = array_merge($params, array_values($hooks));
674 674
 		}
675 675
 
676 676
 		/*
@@ -678,11 +678,11 @@  discard block
 block discarded – undo
678 678
 		 *
679 679
 		 * If we're not limiting by IDs, then include the post_date_gmt clause.
680 680
 		 */
681
-		if ( $limit_ids ) {
682
-			$where .= ' AND ID IN (' . join( ',', $ids ) . ')';
681
+		if ($limit_ids) {
682
+			$where .= ' AND ID IN (' . join(',', $ids) . ')';
683 683
 		} else {
684 684
 			$where   .= ' AND post_date_gmt <= %s';
685
-			$params[] = $date->format( 'Y-m-d H:i:s' );
685
+			$params[] = $date->format('Y-m-d H:i:s');
686 686
 		}
687 687
 
688 688
 		// Add the ORDER BY clause and,ms limit.
@@ -690,10 +690,10 @@  discard block
 block discarded – undo
690 690
 		$params[] = $limit;
691 691
 
692 692
 		// Run the query and gather results.
693
-		$rows_affected = $wpdb->query( $wpdb->prepare( "{$update} {$where} {$order}", $params ) ); // phpcs:ignore // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
693
+		$rows_affected = $wpdb->query($wpdb->prepare("{$update} {$where} {$order}", $params)); // phpcs:ignore // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
694 694
 
695
-		if ( false === $rows_affected ) {
696
-			throw new RuntimeException( __( 'Unable to claim actions. Database error.', 'woocommerce' ) );
695
+		if (false === $rows_affected) {
696
+			throw new RuntimeException(__('Unable to claim actions. Database error.', 'woocommerce'));
697 697
 		}
698 698
 
699 699
 		return (int) $rows_affected;
@@ -710,11 +710,11 @@  discard block
 block discarded – undo
710 710
 	 * @return array IDs of actions in the appropriate group and before the appropriate time.
711 711
 	 * @throws InvalidArgumentException When the group does not exist.
712 712
 	 */
713
-	protected function get_actions_by_group( $group, $limit, DateTime $date ) {
713
+	protected function get_actions_by_group($group, $limit, DateTime $date) {
714 714
 		// Ensure the group exists before continuing.
715
-		if ( ! term_exists( $group, self::GROUP_TAXONOMY ) ) {
715
+		if (!term_exists($group, self::GROUP_TAXONOMY)) {
716 716
 			/* translators: %s is the group name */
717
-			throw new InvalidArgumentException( sprintf( __( 'The group "%s" does not exist.', 'woocommerce' ), $group ) );
717
+			throw new InvalidArgumentException(sprintf(__('The group "%s" does not exist.', 'woocommerce'), $group));
718 718
 		}
719 719
 
720 720
 		// Set up a query for post IDs to use later.
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 			),
735 735
 			'date_query'       => array(
736 736
 				'column'    => 'post_date_gmt',
737
-				'before'    => $date->format( 'Y-m-d H:i' ),
737
+				'before'    => $date->format('Y-m-d H:i'),
738 738
 				'inclusive' => true,
739 739
 			),
740 740
 			'tax_query'        => array( // phpcs:ignore WordPress.DB.SlowDBQuery
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 			),
748 748
 		);
749 749
 
750
-		return $query->query( $query_args );
750
+		return $query->query($query_args);
751 751
 	}
752 752
 
753 753
 	/**
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 	 * @param string $claim_id Claim ID.
757 757
 	 * @return array
758 758
 	 */
759
-	public function find_actions_by_claim_id( $claim_id ) {
759
+	public function find_actions_by_claim_id($claim_id) {
760 760
 		/**
761 761
 		 * Global wpdb object.
762 762
 		 *
@@ -765,8 +765,8 @@  discard block
 block discarded – undo
765 765
 		global $wpdb;
766 766
 
767 767
 		$action_ids  = array();
768
-		$before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object();
769
-		$cut_off     = $before_date->format( 'Y-m-d H:i:s' );
768
+		$before_date = isset($this->claim_before_date) ? $this->claim_before_date : as_get_datetime_object();
769
+		$cut_off     = $before_date->format('Y-m-d H:i:s');
770 770
 
771 771
 		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
772 772
 		$results = $wpdb->get_results(
@@ -781,9 +781,9 @@  discard block
 block discarded – undo
781 781
 
782 782
 		// Verify that the scheduled date for each action is within the expected bounds (in some unusual
783 783
 		// cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify).
784
-		foreach ( $results as $claimed_action ) {
785
-			if ( $claimed_action->post_date_gmt <= $cut_off ) {
786
-				$action_ids[] = absint( $claimed_action->ID );
784
+		foreach ($results as $claimed_action) {
785
+			if ($claimed_action->post_date_gmt <= $cut_off) {
786
+				$action_ids[] = absint($claimed_action->ID);
787 787
 			}
788 788
 		}
789 789
 
@@ -797,12 +797,12 @@  discard block
 block discarded – undo
797 797
 	 * @return void
798 798
 	 * @throws RuntimeException When the claim is not unlocked.
799 799
 	 */
800
-	public function release_claim( ActionScheduler_ActionClaim $claim ) {
801
-		$action_ids = $this->find_actions_by_claim_id( $claim->get_id() );
802
-		if ( empty( $action_ids ) ) {
800
+	public function release_claim(ActionScheduler_ActionClaim $claim) {
801
+		$action_ids = $this->find_actions_by_claim_id($claim->get_id());
802
+		if (empty($action_ids)) {
803 803
 			return; // nothing to do.
804 804
 		}
805
-		$action_id_string = implode( ',', array_map( 'intval', $action_ids ) );
805
+		$action_id_string = implode(',', array_map('intval', $action_ids));
806 806
 		/**
807 807
 		 * Global wpdb object.
808 808
 		 *
@@ -819,9 +819,9 @@  discard block
 block discarded – undo
819 819
 				)
820 820
 			)
821 821
 		);
822
-		if ( false === $result ) {
822
+		if (false === $result) {
823 823
 			/* translators: %s: claim ID */
824
-			throw new RuntimeException( sprintf( __( 'Unable to unlock claim %s. Database error.', 'woocommerce' ), $claim->get_id() ) );
824
+			throw new RuntimeException(sprintf(__('Unable to unlock claim %s. Database error.', 'woocommerce'), $claim->get_id()));
825 825
 		}
826 826
 	}
827 827
 
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 	 * @param string $action_id Action ID.
832 832
 	 * @throws RuntimeException When unable to unlock claim on action ID.
833 833
 	 */
834
-	public function unclaim_action( $action_id ) {
834
+	public function unclaim_action($action_id) {
835 835
 		/**
836 836
 		 * Global wpdb object.
837 837
 		 *
@@ -847,9 +847,9 @@  discard block
 block discarded – undo
847 847
 				self::POST_TYPE
848 848
 			)
849 849
 		);
850
-		if ( false === $result ) {
850
+		if (false === $result) {
851 851
 			/* translators: %s: action ID */
852
-			throw new RuntimeException( sprintf( __( 'Unable to unlock claim on action %s. Database error.', 'woocommerce' ), $action_id ) );
852
+			throw new RuntimeException(sprintf(__('Unable to unlock claim on action %s. Database error.', 'woocommerce'), $action_id));
853 853
 		}
854 854
 	}
855 855
 
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
 	 * @return void
862 862
 	 * @throws RuntimeException When unable to mark failure on action ID.
863 863
 	 */
864
-	public function mark_failure( $action_id ) {
864
+	public function mark_failure($action_id) {
865 865
 		/**
866 866
 		 * Global wpdb object.
867 867
 		 *
@@ -871,11 +871,11 @@  discard block
 block discarded – undo
871 871
 
872 872
 		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
873 873
 		$result = $wpdb->query(
874
-			$wpdb->prepare( "UPDATE {$wpdb->posts} SET post_status = %s WHERE ID = %d AND post_type = %s", self::STATUS_FAILED, $action_id, self::POST_TYPE )
874
+			$wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE ID = %d AND post_type = %s", self::STATUS_FAILED, $action_id, self::POST_TYPE)
875 875
 		);
876
-		if ( false === $result ) {
876
+		if (false === $result) {
877 877
 			/* translators: %s: action ID */
878
-			throw new RuntimeException( sprintf( __( 'Unable to mark failure on action %s. Database error.', 'woocommerce' ), $action_id ) );
878
+			throw new RuntimeException(sprintf(__('Unable to mark failure on action %s. Database error.', 'woocommerce'), $action_id));
879 879
 		}
880 880
 	}
881 881
 
@@ -885,8 +885,8 @@  discard block
 block discarded – undo
885 885
 	 * @param int $action_id Action ID.
886 886
 	 * @return mixed
887 887
 	 */
888
-	public function get_claim_id( $action_id ) {
889
-		return $this->get_post_column( $action_id, 'post_password' );
888
+	public function get_claim_id($action_id) {
889
+		return $this->get_post_column($action_id, 'post_password');
890 890
 	}
891 891
 
892 892
 	/**
@@ -897,14 +897,14 @@  discard block
 block discarded – undo
897 897
 	 * @return mixed
898 898
 	 * @throws InvalidArgumentException When the action ID is invalid.
899 899
 	 */
900
-	public function get_status( $action_id ) {
901
-		$status = $this->get_post_column( $action_id, 'post_status' );
900
+	public function get_status($action_id) {
901
+		$status = $this->get_post_column($action_id, 'post_status');
902 902
 
903
-		if ( null === $status ) {
904
-			throw new InvalidArgumentException( __( 'Invalid action ID. No status found.', 'woocommerce' ) );
903
+		if (null === $status) {
904
+			throw new InvalidArgumentException(__('Invalid action ID. No status found.', 'woocommerce'));
905 905
 		}
906 906
 
907
-		return $this->get_action_status_by_post_status( $status );
907
+		return $this->get_action_status_by_post_status($status);
908 908
 	}
909 909
 
910 910
 	/**
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
 	 *
916 916
 	 * @return string|null
917 917
 	 */
918
-	private function get_post_column( $action_id, $column_name ) {
918
+	private function get_post_column($action_id, $column_name) {
919 919
 		/**
920 920
 		 * Global wpdb object.
921 921
 		 *
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
 	 *
939 939
 	 * @param string $action_id Action ID.
940 940
 	 */
941
-	public function log_execution( $action_id ) {
941
+	public function log_execution($action_id) {
942 942
 		/**
943 943
 		 * Global wpdb object.
944 944
 		 *
@@ -951,8 +951,8 @@  discard block
 block discarded – undo
951 951
 			$wpdb->prepare(
952 952
 				"UPDATE {$wpdb->posts} SET menu_order = menu_order+1, post_status=%s, post_modified_gmt = %s, post_modified = %s WHERE ID = %d AND post_type = %s",
953 953
 				self::STATUS_RUNNING,
954
-				current_time( 'mysql', true ),
955
-				current_time( 'mysql' ),
954
+				current_time('mysql', true),
955
+				current_time('mysql'),
956 956
 				$action_id,
957 957
 				self::POST_TYPE
958 958
 			)
@@ -967,14 +967,14 @@  discard block
 block discarded – undo
967 967
 	 * @throws InvalidArgumentException When the action ID is invalid.
968 968
 	 * @throws RuntimeException         When there was an error executing the action.
969 969
 	 */
970
-	public function mark_complete( $action_id ) {
971
-		$post = get_post( $action_id );
972
-		if ( empty( $post ) || ( self::POST_TYPE !== $post->post_type ) ) {
970
+	public function mark_complete($action_id) {
971
+		$post = get_post($action_id);
972
+		if (empty($post) || (self::POST_TYPE !== $post->post_type)) {
973 973
 			/* translators: %s is the action ID */
974
-			throw new InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) );
974
+			throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'woocommerce'), $action_id));
975 975
 		}
976
-		add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 );
977
-		add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 );
976
+		add_filter('wp_insert_post_data', array($this, 'filter_insert_post_data'), 10, 1);
977
+		add_filter('pre_wp_unique_post_slug', array($this, 'set_unique_post_slug'), 10, 5);
978 978
 		$result = wp_update_post(
979 979
 			array(
980 980
 				'ID'          => $action_id,
@@ -982,10 +982,10 @@  discard block
 block discarded – undo
982 982
 			),
983 983
 			true
984 984
 		);
985
-		remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 );
986
-		remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 );
987
-		if ( is_wp_error( $result ) ) {
988
-			throw new RuntimeException( $result->get_error_message() );
985
+		remove_filter('wp_insert_post_data', array($this, 'filter_insert_post_data'), 10);
986
+		remove_filter('pre_wp_unique_post_slug', array($this, 'set_unique_post_slug'), 10);
987
+		if (is_wp_error($result)) {
988
+			throw new RuntimeException($result->get_error_message());
989 989
 		}
990 990
 
991 991
 		/**
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
 		 *
996 996
 		 * @param int $action_id Action ID.
997 997
 		 */
998
-		do_action( 'action_scheduler_completed_action', $action_id );
998
+		do_action('action_scheduler_completed_action', $action_id);
999 999
 	}
1000 1000
 
1001 1001
 	/**
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
 	 *
1004 1004
 	 * @param int $action_id Action ID.
1005 1005
 	 */
1006
-	public function mark_migrated( $action_id ) {
1006
+	public function mark_migrated($action_id) {
1007 1007
 		wp_update_post(
1008 1008
 			array(
1009 1009
 				'ID'          => $action_id,
@@ -1018,12 +1018,12 @@  discard block
 block discarded – undo
1018 1018
 	 * @param [type] $setting - Setting value.
1019 1019
 	 * @return bool
1020 1020
 	 */
1021
-	public function migration_dependencies_met( $setting ) {
1021
+	public function migration_dependencies_met($setting) {
1022 1022
 		global $wpdb;
1023 1023
 
1024
-		$dependencies_met = get_transient( self::DEPENDENCIES_MET );
1025
-		if ( empty( $dependencies_met ) ) {
1026
-			$maximum_args_length = apply_filters( 'action_scheduler_maximum_args_length', 191 );
1024
+		$dependencies_met = get_transient(self::DEPENDENCIES_MET);
1025
+		if (empty($dependencies_met)) {
1026
+			$maximum_args_length = apply_filters('action_scheduler_maximum_args_length', 191);
1027 1027
 			$found_action        = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1028 1028
 				$wpdb->prepare(
1029 1029
 					"SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND CHAR_LENGTH(post_content) > %d LIMIT 1",
@@ -1031,8 +1031,8 @@  discard block
 block discarded – undo
1031 1031
 					self::POST_TYPE
1032 1032
 				)
1033 1033
 			);
1034
-			$dependencies_met    = $found_action ? 'no' : 'yes';
1035
-			set_transient( self::DEPENDENCIES_MET, $dependencies_met, DAY_IN_SECONDS );
1034
+			$dependencies_met = $found_action ? 'no' : 'yes';
1035
+			set_transient(self::DEPENDENCIES_MET, $dependencies_met, DAY_IN_SECONDS);
1036 1036
 		}
1037 1037
 
1038 1038
 		return 'yes' === $dependencies_met ? $setting : false;
@@ -1047,13 +1047,13 @@  discard block
 block discarded – undo
1047 1047
 	 *
1048 1048
 	 * @param ActionScheduler_Action $action Action object.
1049 1049
 	 */
1050
-	protected function validate_action( ActionScheduler_Action $action ) {
1050
+	protected function validate_action(ActionScheduler_Action $action) {
1051 1051
 		try {
1052
-			parent::validate_action( $action );
1053
-		} catch ( Exception $e ) {
1052
+			parent::validate_action($action);
1053
+		} catch (Exception $e) {
1054 1054
 			/* translators: %s is the error message */
1055
-			$message = sprintf( __( '%s Support for strings longer than this will be removed in a future version.', 'woocommerce' ), $e->getMessage() );
1056
-			_doing_it_wrong( 'ActionScheduler_Action::$args', esc_html( $message ), '2.1.0' );
1055
+			$message = sprintf(__('%s Support for strings longer than this will be removed in a future version.', 'woocommerce'), $e->getMessage());
1056
+			_doing_it_wrong('ActionScheduler_Action::$args', esc_html($message), '2.1.0');
1057 1057
 		}
1058 1058
 	}
1059 1059
 
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
 	 * (@codeCoverageIgnore)
1062 1062
 	 */
1063 1063
 	public function init() {
1064
-		add_filter( 'action_scheduler_migration_dependencies_met', array( $this, 'migration_dependencies_met' ) );
1064
+		add_filter('action_scheduler_migration_dependencies_met', array($this, 'migration_dependencies_met'));
1065 1065
 
1066 1066
 		$post_type_registrar = new ActionScheduler_wpPostStore_PostTypeRegistrar();
1067 1067
 		$post_type_registrar->register();
Please login to merge, or discard this patch.
classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  */
7 7
 class ActionScheduler_wpPostStore_PostTypeRegistrar {
8 8
 	public function register() {
9
-		register_post_type( ActionScheduler_wpPostStore::POST_TYPE, $this->post_type_args() );
9
+		register_post_type(ActionScheduler_wpPostStore::POST_TYPE, $this->post_type_args());
10 10
 	}
11 11
 
12 12
 	/**
@@ -16,30 +16,30 @@  discard block
 block discarded – undo
16 16
 	 */
17 17
 	protected function post_type_args() {
18 18
 		$args = array(
19
-			'label' => __( 'Scheduled Actions', 'woocommerce' ),
20
-			'description' => __( 'Scheduled actions are hooks triggered on a cetain date and time.', 'woocommerce' ),
19
+			'label' => __('Scheduled Actions', 'woocommerce'),
20
+			'description' => __('Scheduled actions are hooks triggered on a cetain date and time.', 'woocommerce'),
21 21
 			'public' => false,
22 22
 			'map_meta_cap' => true,
23 23
 			'hierarchical' => false,
24
-			'supports' => array('title', 'editor','comments'),
24
+			'supports' => array('title', 'editor', 'comments'),
25 25
 			'rewrite' => false,
26 26
 			'query_var' => false,
27 27
 			'can_export' => true,
28 28
 			'ep_mask' => EP_NONE,
29 29
 			'labels' => array(
30
-				'name' => __( 'Scheduled Actions', 'woocommerce' ),
31
-				'singular_name' => __( 'Scheduled Action', 'woocommerce' ),
32
-				'menu_name' => _x( 'Scheduled Actions', 'Admin menu name', 'woocommerce' ),
33
-				'add_new' => __( 'Add', 'woocommerce' ),
34
-				'add_new_item' => __( 'Add New Scheduled Action', 'woocommerce' ),
35
-				'edit' => __( 'Edit', 'woocommerce' ),
36
-				'edit_item' => __( 'Edit Scheduled Action', 'woocommerce' ),
37
-				'new_item' => __( 'New Scheduled Action', 'woocommerce' ),
38
-				'view' => __( 'View Action', 'woocommerce' ),
39
-				'view_item' => __( 'View Action', 'woocommerce' ),
40
-				'search_items' => __( 'Search Scheduled Actions', 'woocommerce' ),
41
-				'not_found' => __( 'No actions found', 'woocommerce' ),
42
-				'not_found_in_trash' => __( 'No actions found in trash', 'woocommerce' ),
30
+				'name' => __('Scheduled Actions', 'woocommerce'),
31
+				'singular_name' => __('Scheduled Action', 'woocommerce'),
32
+				'menu_name' => _x('Scheduled Actions', 'Admin menu name', 'woocommerce'),
33
+				'add_new' => __('Add', 'woocommerce'),
34
+				'add_new_item' => __('Add New Scheduled Action', 'woocommerce'),
35
+				'edit' => __('Edit', 'woocommerce'),
36
+				'edit_item' => __('Edit Scheduled Action', 'woocommerce'),
37
+				'new_item' => __('New Scheduled Action', 'woocommerce'),
38
+				'view' => __('View Action', 'woocommerce'),
39
+				'view_item' => __('View Action', 'woocommerce'),
40
+				'search_items' => __('Search Scheduled Actions', 'woocommerce'),
41
+				'not_found' => __('No actions found', 'woocommerce'),
42
+				'not_found_in_trash' => __('No actions found in trash', 'woocommerce'),
43 43
 			),
44 44
 		);
45 45
 
Please login to merge, or discard this patch.
packages/action-scheduler/classes/ActionScheduler_QueueRunner.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	 * @codeCoverageIgnore
20 20
 	 */
21 21
 	public static function instance() {
22
-		if ( empty(self::$runner) ) {
22
+		if (empty(self::$runner)) {
23 23
 			$class = apply_filters('action_scheduler_queue_runner_class', 'ActionScheduler_QueueRunner');
24 24
 			self::$runner = new $class();
25 25
 		}
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * @param ActionScheduler_FatalErrorMonitor $monitor
34 34
 	 * @param ActionScheduler_QueueCleaner      $cleaner
35 35
 	 */
36
-	public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null, ActionScheduler_AsyncRequest_QueueRunner $async_request = null ) {
37
-		parent::__construct( $store, $monitor, $cleaner );
36
+	public function __construct(ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null, ActionScheduler_AsyncRequest_QueueRunner $async_request = null) {
37
+		parent::__construct($store, $monitor, $cleaner);
38 38
 
39
-		if ( is_null( $async_request ) ) {
40
-			$async_request = new ActionScheduler_AsyncRequest_QueueRunner( $this->store );
39
+		if (is_null($async_request)) {
40
+			$async_request = new ActionScheduler_AsyncRequest_QueueRunner($this->store);
41 41
 		}
42 42
 
43 43
 		$this->async_request = $async_request;
@@ -48,22 +48,22 @@  discard block
 block discarded – undo
48 48
 	 */
49 49
 	public function init() {
50 50
 
51
-		add_filter( 'cron_schedules', array( self::instance(), 'add_wp_cron_schedule' ) );
51
+		add_filter('cron_schedules', array(self::instance(), 'add_wp_cron_schedule'));
52 52
 
53 53
 		// Check for and remove any WP Cron hook scheduled by Action Scheduler < 3.0.0, which didn't include the $context param
54
-		$next_timestamp = wp_next_scheduled( self::WP_CRON_HOOK );
55
-		if ( $next_timestamp ) {
56
-			wp_unschedule_event( $next_timestamp, self::WP_CRON_HOOK );
54
+		$next_timestamp = wp_next_scheduled(self::WP_CRON_HOOK);
55
+		if ($next_timestamp) {
56
+			wp_unschedule_event($next_timestamp, self::WP_CRON_HOOK);
57 57
 		}
58 58
 
59
-		$cron_context = array( 'WP Cron' );
59
+		$cron_context = array('WP Cron');
60 60
 
61
-		if ( ! wp_next_scheduled( self::WP_CRON_HOOK, $cron_context ) ) {
62
-			$schedule = apply_filters( 'action_scheduler_run_schedule', self::WP_CRON_SCHEDULE );
63
-			wp_schedule_event( time(), $schedule, self::WP_CRON_HOOK, $cron_context );
61
+		if (!wp_next_scheduled(self::WP_CRON_HOOK, $cron_context)) {
62
+			$schedule = apply_filters('action_scheduler_run_schedule', self::WP_CRON_SCHEDULE);
63
+			wp_schedule_event(time(), $schedule, self::WP_CRON_HOOK, $cron_context);
64 64
 		}
65 65
 
66
-		add_action( self::WP_CRON_HOOK, array( self::instance(), 'run' ) );
66
+		add_action(self::WP_CRON_HOOK, array(self::instance(), 'run'));
67 67
 		$this->hook_dispatch_async_request();
68 68
 	}
69 69
 
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 	 * Hook check for dispatching an async request.
72 72
 	 */
73 73
 	public function hook_dispatch_async_request() {
74
-		add_action( 'shutdown', array( $this, 'maybe_dispatch_async_request' ) );
74
+		add_action('shutdown', array($this, 'maybe_dispatch_async_request'));
75 75
 	}
76 76
 
77 77
 	/**
78 78
 	 * Unhook check for dispatching an async request.
79 79
 	 */
80 80
 	public function unhook_dispatch_async_request() {
81
-		remove_action( 'shutdown', array( $this, 'maybe_dispatch_async_request' ) );
81
+		remove_action('shutdown', array($this, 'maybe_dispatch_async_request'));
82 82
 	}
83 83
 
84 84
 	/**
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
 	 * should dispatch a request to process pending actions.
101 101
 	 */
102 102
 	public function maybe_dispatch_async_request() {
103
-		if ( is_admin() && ! ActionScheduler::lock()->is_locked( 'async-request-runner' ) ) {
103
+		if (is_admin() && !ActionScheduler::lock()->is_locked('async-request-runner')) {
104 104
 			// Only start an async queue at most once every 60 seconds
105
-			ActionScheduler::lock()->set( 'async-request-runner' );
105
+			ActionScheduler::lock()->set('async-request-runner');
106 106
 			$this->async_request->maybe_dispatch();
107 107
 		}
108 108
 	}
@@ -120,21 +120,21 @@  discard block
 block discarded – undo
120 120
 	 *        Generally, this should be capitalised and not localised as it's a proper noun.
121 121
 	 * @return int The number of actions processed.
122 122
 	 */
123
-	public function run( $context = 'WP Cron' ) {
123
+	public function run($context = 'WP Cron') {
124 124
 		ActionScheduler_Compatibility::raise_memory_limit();
125
-		ActionScheduler_Compatibility::raise_time_limit( $this->get_time_limit() );
126
-		do_action( 'action_scheduler_before_process_queue' );
125
+		ActionScheduler_Compatibility::raise_time_limit($this->get_time_limit());
126
+		do_action('action_scheduler_before_process_queue');
127 127
 		$this->run_cleanup();
128 128
 		$processed_actions = 0;
129
-		if ( false === $this->has_maximum_concurrent_batches() ) {
130
-			$batch_size = apply_filters( 'action_scheduler_queue_runner_batch_size', 25 );
129
+		if (false === $this->has_maximum_concurrent_batches()) {
130
+			$batch_size = apply_filters('action_scheduler_queue_runner_batch_size', 25);
131 131
 			do {
132
-				$processed_actions_in_batch = $this->do_batch( $batch_size, $context );
132
+				$processed_actions_in_batch = $this->do_batch($batch_size, $context);
133 133
 				$processed_actions         += $processed_actions_in_batch;
134
-			} while ( $processed_actions_in_batch > 0 && ! $this->batch_limits_exceeded( $processed_actions ) ); // keep going until we run out of actions, time, or memory
134
+			} while ($processed_actions_in_batch > 0 && !$this->batch_limits_exceeded($processed_actions)); // keep going until we run out of actions, time, or memory
135 135
 		}
136 136
 
137
-		do_action( 'action_scheduler_after_process_queue' );
137
+		do_action('action_scheduler_after_process_queue');
138 138
 		return $processed_actions;
139 139
 	}
140 140
 
@@ -149,20 +149,20 @@  discard block
 block discarded – undo
149 149
 	 *        Generally, this should be capitalised and not localised as it's a proper noun.
150 150
 	 * @return int The number of actions processed.
151 151
 	 */
152
-	protected function do_batch( $size = 100, $context = '' ) {
152
+	protected function do_batch($size = 100, $context = '') {
153 153
 		$claim = $this->store->stake_claim($size);
154 154
 		$this->monitor->attach($claim);
155 155
 		$processed_actions = 0;
156 156
 
157
-		foreach ( $claim->get_actions() as $action_id ) {
157
+		foreach ($claim->get_actions() as $action_id) {
158 158
 			// bail if we lost the claim
159
-			if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $claim->get_id() ) ) ) {
159
+			if (!in_array($action_id, $this->store->find_actions_by_claim_id($claim->get_id()))) {
160 160
 				break;
161 161
 			}
162
-			$this->process_action( $action_id, $context );
162
+			$this->process_action($action_id, $context);
163 163
 			$processed_actions++;
164 164
 
165
-			if ( $this->batch_limits_exceeded( $processed_actions ) ) {
165
+			if ($this->batch_limits_exceeded($processed_actions)) {
166 166
 				break;
167 167
 			}
168 168
 		}
@@ -181,15 +181,15 @@  discard block
 block discarded – undo
181 181
 	 * add_filter( 'action_scheduler_queue_runner_flush_cache', '__return_true' );
182 182
 	 */
183 183
 	protected function clear_caches() {
184
-		if ( ! wp_using_ext_object_cache() || apply_filters( 'action_scheduler_queue_runner_flush_cache', false ) ) {
184
+		if (!wp_using_ext_object_cache() || apply_filters('action_scheduler_queue_runner_flush_cache', false)) {
185 185
 			wp_cache_flush();
186 186
 		}
187 187
 	}
188 188
 
189
-	public function add_wp_cron_schedule( $schedules ) {
189
+	public function add_wp_cron_schedule($schedules) {
190 190
 		$schedules['every_minute'] = array(
191 191
 			'interval' => 60, // in seconds
192
-			'display'  => __( 'Every minute', 'woocommerce' ),
192
+			'display'  => __('Every minute', 'woocommerce'),
193 193
 		);
194 194
 
195 195
 		return $schedules;
Please login to merge, or discard this patch.
packages/action-scheduler/classes/abstracts/ActionScheduler_Logger.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 	 * @return ActionScheduler_Logger
12 12
 	 */
13 13
 	public static function instance() {
14
-		if ( empty(self::$logger) ) {
14
+		if (empty(self::$logger)) {
15 15
 			$class = apply_filters('action_scheduler_logger_class', 'ActionScheduler_wpCommentLogger');
16 16
 			self::$logger = new $class();
17 17
 		}
@@ -25,21 +25,21 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @return string The log entry ID
27 27
 	 */
28
-	abstract public function log( $action_id, $message, DateTime $date = NULL );
28
+	abstract public function log($action_id, $message, DateTime $date = NULL);
29 29
 
30 30
 	/**
31 31
 	 * @param string $entry_id
32 32
 	 *
33 33
 	 * @return ActionScheduler_LogEntry
34 34
 	 */
35
-	abstract public function get_entry( $entry_id );
35
+	abstract public function get_entry($entry_id);
36 36
 
37 37
 	/**
38 38
 	 * @param string $action_id
39 39
 	 *
40 40
 	 * @return ActionScheduler_LogEntry[]
41 41
 	 */
42
-	abstract public function get_logs( $action_id );
42
+	abstract public function get_logs($action_id);
43 43
 
44 44
 
45 45
 	/**
@@ -47,90 +47,90 @@  discard block
 block discarded – undo
47 47
 	 */
48 48
 	public function init() {
49 49
 		$this->hook_stored_action();
50
-		add_action( 'action_scheduler_canceled_action', array( $this, 'log_canceled_action' ), 10, 1 );
51
-		add_action( 'action_scheduler_begin_execute', array( $this, 'log_started_action' ), 10, 2 );
52
-		add_action( 'action_scheduler_after_execute', array( $this, 'log_completed_action' ), 10, 3 );
53
-		add_action( 'action_scheduler_failed_execution', array( $this, 'log_failed_action' ), 10, 3 );
54
-		add_action( 'action_scheduler_failed_action', array( $this, 'log_timed_out_action' ), 10, 2 );
55
-		add_action( 'action_scheduler_unexpected_shutdown', array( $this, 'log_unexpected_shutdown' ), 10, 2 );
56
-		add_action( 'action_scheduler_reset_action', array( $this, 'log_reset_action' ), 10, 1 );
57
-		add_action( 'action_scheduler_execution_ignored', array( $this, 'log_ignored_action' ), 10, 2 );
58
-		add_action( 'action_scheduler_failed_fetch_action', array( $this, 'log_failed_fetch_action' ), 10, 2 );
59
-		add_action( 'action_scheduler_failed_to_schedule_next_instance', array( $this, 'log_failed_schedule_next_instance' ), 10, 2 );
60
-		add_action( 'action_scheduler_bulk_cancel_actions', array( $this, 'bulk_log_cancel_actions' ), 10, 1 );
50
+		add_action('action_scheduler_canceled_action', array($this, 'log_canceled_action'), 10, 1);
51
+		add_action('action_scheduler_begin_execute', array($this, 'log_started_action'), 10, 2);
52
+		add_action('action_scheduler_after_execute', array($this, 'log_completed_action'), 10, 3);
53
+		add_action('action_scheduler_failed_execution', array($this, 'log_failed_action'), 10, 3);
54
+		add_action('action_scheduler_failed_action', array($this, 'log_timed_out_action'), 10, 2);
55
+		add_action('action_scheduler_unexpected_shutdown', array($this, 'log_unexpected_shutdown'), 10, 2);
56
+		add_action('action_scheduler_reset_action', array($this, 'log_reset_action'), 10, 1);
57
+		add_action('action_scheduler_execution_ignored', array($this, 'log_ignored_action'), 10, 2);
58
+		add_action('action_scheduler_failed_fetch_action', array($this, 'log_failed_fetch_action'), 10, 2);
59
+		add_action('action_scheduler_failed_to_schedule_next_instance', array($this, 'log_failed_schedule_next_instance'), 10, 2);
60
+		add_action('action_scheduler_bulk_cancel_actions', array($this, 'bulk_log_cancel_actions'), 10, 1);
61 61
 	}
62 62
 
63 63
 	public function hook_stored_action() {
64
-		add_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
64
+		add_action('action_scheduler_stored_action', array($this, 'log_stored_action'));
65 65
 	}
66 66
 
67 67
 	public function unhook_stored_action() {
68
-		remove_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
68
+		remove_action('action_scheduler_stored_action', array($this, 'log_stored_action'));
69 69
 	}
70 70
 
71
-	public function log_stored_action( $action_id ) {
72
-		$this->log( $action_id, __( 'action created', 'woocommerce' ) );
71
+	public function log_stored_action($action_id) {
72
+		$this->log($action_id, __('action created', 'woocommerce'));
73 73
 	}
74 74
 
75
-	public function log_canceled_action( $action_id ) {
76
-		$this->log( $action_id, __( 'action canceled', 'woocommerce' ) );
75
+	public function log_canceled_action($action_id) {
76
+		$this->log($action_id, __('action canceled', 'woocommerce'));
77 77
 	}
78 78
 
79
-	public function log_started_action( $action_id, $context = '' ) {
80
-		if ( ! empty( $context ) ) {
79
+	public function log_started_action($action_id, $context = '') {
80
+		if (!empty($context)) {
81 81
 			/* translators: %s: context */
82
-			$message = sprintf( __( 'action started via %s', 'woocommerce' ), $context );
82
+			$message = sprintf(__('action started via %s', 'woocommerce'), $context);
83 83
 		} else {
84
-			$message = __( 'action started', 'woocommerce' );
84
+			$message = __('action started', 'woocommerce');
85 85
 		}
86
-		$this->log( $action_id, $message );
86
+		$this->log($action_id, $message);
87 87
 	}
88 88
 
89
-	public function log_completed_action( $action_id, $action = NULL, $context = '' ) {
90
-		if ( ! empty( $context ) ) {
89
+	public function log_completed_action($action_id, $action = NULL, $context = '') {
90
+		if (!empty($context)) {
91 91
 			/* translators: %s: context */
92
-			$message = sprintf( __( 'action complete via %s', 'woocommerce' ), $context );
92
+			$message = sprintf(__('action complete via %s', 'woocommerce'), $context);
93 93
 		} else {
94
-			$message = __( 'action complete', 'woocommerce' );
94
+			$message = __('action complete', 'woocommerce');
95 95
 		}
96
-		$this->log( $action_id, $message );
96
+		$this->log($action_id, $message);
97 97
 	}
98 98
 
99
-	public function log_failed_action( $action_id, Exception $exception, $context = '' ) {
100
-		if ( ! empty( $context ) ) {
99
+	public function log_failed_action($action_id, Exception $exception, $context = '') {
100
+		if (!empty($context)) {
101 101
 			/* translators: 1: context 2: exception message */
102
-			$message = sprintf( __( 'action failed via %1$s: %2$s', 'woocommerce' ), $context, $exception->getMessage() );
102
+			$message = sprintf(__('action failed via %1$s: %2$s', 'woocommerce'), $context, $exception->getMessage());
103 103
 		} else {
104 104
 			/* translators: %s: exception message */
105
-			$message = sprintf( __( 'action failed: %s', 'woocommerce' ), $exception->getMessage() );
105
+			$message = sprintf(__('action failed: %s', 'woocommerce'), $exception->getMessage());
106 106
 		}
107
-		$this->log( $action_id, $message );
107
+		$this->log($action_id, $message);
108 108
 	}
109 109
 
110
-	public function log_timed_out_action( $action_id, $timeout ) {
110
+	public function log_timed_out_action($action_id, $timeout) {
111 111
 		/* translators: %s: amount of time */
112
-		$this->log( $action_id, sprintf( __( 'action marked as failed after %s seconds. Unknown error occurred. Check server, PHP and database error logs to diagnose cause.', 'woocommerce' ), $timeout ) );
112
+		$this->log($action_id, sprintf(__('action marked as failed after %s seconds. Unknown error occurred. Check server, PHP and database error logs to diagnose cause.', 'woocommerce'), $timeout));
113 113
 	}
114 114
 
115
-	public function log_unexpected_shutdown( $action_id, $error ) {
116
-		if ( ! empty( $error ) ) {
115
+	public function log_unexpected_shutdown($action_id, $error) {
116
+		if (!empty($error)) {
117 117
 			/* translators: 1: error message 2: filename 3: line */
118
-			$this->log( $action_id, sprintf( __( 'unexpected shutdown: PHP Fatal error %1$s in %2$s on line %3$s', 'woocommerce' ), $error['message'], $error['file'], $error['line'] ) );
118
+			$this->log($action_id, sprintf(__('unexpected shutdown: PHP Fatal error %1$s in %2$s on line %3$s', 'woocommerce'), $error['message'], $error['file'], $error['line']));
119 119
 		}
120 120
 	}
121 121
 
122
-	public function log_reset_action( $action_id ) {
123
-		$this->log( $action_id, __( 'action reset', 'woocommerce' ) );
122
+	public function log_reset_action($action_id) {
123
+		$this->log($action_id, __('action reset', 'woocommerce'));
124 124
 	}
125 125
 
126
-	public function log_ignored_action( $action_id, $context = '' ) {
127
-		if ( ! empty( $context ) ) {
126
+	public function log_ignored_action($action_id, $context = '') {
127
+		if (!empty($context)) {
128 128
 			/* translators: %s: context */
129
-			$message = sprintf( __( 'action ignored via %s', 'woocommerce' ), $context );
129
+			$message = sprintf(__('action ignored via %s', 'woocommerce'), $context);
130 130
 		} else {
131
-			$message = __( 'action ignored', 'woocommerce' );
131
+			$message = __('action ignored', 'woocommerce');
132 132
 		}
133
-		$this->log( $action_id, $message );
133
+		$this->log($action_id, $message);
134 134
 	}
135 135
 
136 136
 	/**
@@ -139,21 +139,21 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @return ActionScheduler_LogEntry[]
141 141
 	 */
142
-	public function log_failed_fetch_action( $action_id, Exception $exception = NULL ) {
142
+	public function log_failed_fetch_action($action_id, Exception $exception = NULL) {
143 143
 
144
-		if ( ! is_null( $exception ) ) {
144
+		if (!is_null($exception)) {
145 145
 			/* translators: %s: exception message */
146
-			$log_message = sprintf( __( 'There was a failure fetching this action: %s', 'woocommerce' ), $exception->getMessage() );
146
+			$log_message = sprintf(__('There was a failure fetching this action: %s', 'woocommerce'), $exception->getMessage());
147 147
 		} else {
148
-			$log_message = __( 'There was a failure fetching this action', 'woocommerce' );
148
+			$log_message = __('There was a failure fetching this action', 'woocommerce');
149 149
 		}
150 150
 
151
-		$this->log( $action_id, $log_message );
151
+		$this->log($action_id, $log_message);
152 152
 	}
153 153
 
154
-	public function log_failed_schedule_next_instance( $action_id, Exception $exception ) {
154
+	public function log_failed_schedule_next_instance($action_id, Exception $exception) {
155 155
 		/* translators: %s: exception message */
156
-		$this->log( $action_id, sprintf( __( 'There was a failure scheduling the next instance of this action: %s', 'woocommerce' ), $exception->getMessage() ) );
156
+		$this->log($action_id, sprintf(__('There was a failure scheduling the next instance of this action: %s', 'woocommerce'), $exception->getMessage()));
157 157
 	}
158 158
 
159 159
 	/**
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
 	 *
165 165
 	 * @param array $action_ids List of action ID.
166 166
 	 */
167
-	public function bulk_log_cancel_actions( $action_ids ) {
168
-		if ( empty( $action_ids ) ) {
167
+	public function bulk_log_cancel_actions($action_ids) {
168
+		if (empty($action_ids)) {
169 169
 			return;
170 170
 		}
171 171
 
172
-		foreach ( $action_ids as $action_id ) {
173
-			$this->log_canceled_action( $action_id );
172
+		foreach ($action_ids as $action_id) {
173
+			$this->log_canceled_action($action_id);
174 174
 		}
175 175
 	}
176 176
 }
Please login to merge, or discard this patch.
action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @param DateTime $date The date & time to run the action.
24 24
 	 */
25
-	public function __construct( DateTime $date ) {
25
+	public function __construct(DateTime $date) {
26 26
 		$this->scheduled_date = $date;
27 27
 	}
28 28
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 * @param DateTime $after
40 40
 	 * @return DateTime
41 41
 	 */
42
-	abstract protected function calculate_next( DateTime $after );
42
+	abstract protected function calculate_next(DateTime $after);
43 43
 
44 44
 	/**
45 45
 	 * Get the next date & time when this schedule should run after a given date & time.
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 * @param DateTime $after
48 48
 	 * @return DateTime|null
49 49
 	 */
50
-	public function get_next( DateTime $after ) {
50
+	public function get_next(DateTime $after) {
51 51
 		$after = clone $after;
52
-		if ( $after > $this->scheduled_date ) {
53
-			$after = $this->calculate_next( $after );
52
+		if ($after > $this->scheduled_date) {
53
+			$after = $this->calculate_next($after);
54 54
 			return $after;
55 55
 		}
56 56
 		return clone $this->scheduled_date;
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	}
78 78
 
79 79
 	public function __wakeup() {
80
-		$this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp );
81
-		unset( $this->scheduled_timestamp );
80
+		$this->scheduled_date = as_get_datetime_object($this->scheduled_timestamp);
81
+		unset($this->scheduled_timestamp);
82 82
 	}
83 83
 }
Please login to merge, or discard this patch.
packages/action-scheduler/classes/abstracts/ActionScheduler_Store.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @return int The action ID
28 28
 	 */
29
-	abstract public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = NULL );
29
+	abstract public function save_action(ActionScheduler_Action $action, DateTime $scheduled_date = NULL);
30 30
 
31 31
 	/**
32 32
 	 * @param string $action_id
33 33
 	 *
34 34
 	 * @return ActionScheduler_Action
35 35
 	 */
36
-	abstract public function fetch_action( $action_id );
36
+	abstract public function fetch_action($action_id);
37 37
 
38 38
 	/**
39 39
 	 * Find an action.
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @return string|null ID of the next action matching the criteria or NULL if not found.
47 47
 	 */
48
-	public function find_action( $hook, $params = array() ) {
48
+	public function find_action($hook, $params = array()) {
49 49
 		$params = wp_parse_args(
50 50
 			$params,
51 51
 			array(
@@ -60,17 +60,17 @@  discard block
 block discarded – undo
60 60
 		$params['orderby']  = 'date';
61 61
 		$params['per_page'] = 1;
62 62
 
63
-		if ( ! empty( $params['status'] ) ) {
64
-			if ( self::STATUS_PENDING === $params['status'] ) {
63
+		if (!empty($params['status'])) {
64
+			if (self::STATUS_PENDING === $params['status']) {
65 65
 				$params['order'] = 'ASC'; // Find the next action that matches.
66 66
 			} else {
67 67
 				$params['order'] = 'DESC'; // Find the most recent action that matches.
68 68
 			}
69 69
 		}
70 70
 
71
-		$results = $this->query_actions( $params );
71
+		$results = $this->query_actions($params);
72 72
 
73
-		return empty( $results ) ? null : $results[0];
73
+		return empty($results) ? null : $results[0];
74 74
 	}
75 75
 
76 76
 	/**
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 * @return string|array|null The IDs of actions matching the query. Null on failure.
101 101
 	 */
102
-	abstract public function query_actions( $query = array(), $query_type = 'select' );
102
+	abstract public function query_actions($query = array(), $query_type = 'select');
103 103
 
104 104
 	/**
105 105
 	 * Run query to get a single action ID.
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @return int|null
114 114
 	 */
115
-	public function query_action( $query ) {
115
+	public function query_action($query) {
116 116
 		$query['per_page'] = 1;
117 117
 		$query['offset']   = 0;
118
-		$results           = $this->query_actions( $query );
118
+		$results           = $this->query_actions($query);
119 119
 
120
-		if ( empty( $results ) ) {
120
+		if (empty($results)) {
121 121
 			return null;
122 122
 		} else {
123 123
 			return (int) $results[0];
@@ -134,19 +134,19 @@  discard block
 block discarded – undo
134 134
 	/**
135 135
 	 * @param string $action_id
136 136
 	 */
137
-	abstract public function cancel_action( $action_id );
137
+	abstract public function cancel_action($action_id);
138 138
 
139 139
 	/**
140 140
 	 * @param string $action_id
141 141
 	 */
142
-	abstract public function delete_action( $action_id );
142
+	abstract public function delete_action($action_id);
143 143
 
144 144
 	/**
145 145
 	 * @param string $action_id
146 146
 	 *
147 147
 	 * @return DateTime The date the action is schedule to run, or the date that it ran.
148 148
 	 */
149
-	abstract public function get_date( $action_id );
149
+	abstract public function get_date($action_id);
150 150
 
151 151
 
152 152
 	/**
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @return ActionScheduler_ActionClaim
159 159
 	 */
160
-	abstract public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' );
160
+	abstract public function stake_claim($max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '');
161 161
 
162 162
 	/**
163 163
 	 * @return int
@@ -167,53 +167,53 @@  discard block
 block discarded – undo
167 167
 	/**
168 168
 	 * @param ActionScheduler_ActionClaim $claim
169 169
 	 */
170
-	abstract public function release_claim( ActionScheduler_ActionClaim $claim );
170
+	abstract public function release_claim(ActionScheduler_ActionClaim $claim);
171 171
 
172 172
 	/**
173 173
 	 * @param string $action_id
174 174
 	 */
175
-	abstract public function unclaim_action( $action_id );
175
+	abstract public function unclaim_action($action_id);
176 176
 
177 177
 	/**
178 178
 	 * @param string $action_id
179 179
 	 */
180
-	abstract public function mark_failure( $action_id );
180
+	abstract public function mark_failure($action_id);
181 181
 
182 182
 	/**
183 183
 	 * @param string $action_id
184 184
 	 */
185
-	abstract public function log_execution( $action_id );
185
+	abstract public function log_execution($action_id);
186 186
 
187 187
 	/**
188 188
 	 * @param string $action_id
189 189
 	 */
190
-	abstract public function mark_complete( $action_id );
190
+	abstract public function mark_complete($action_id);
191 191
 
192 192
 	/**
193 193
 	 * @param string $action_id
194 194
 	 *
195 195
 	 * @return string
196 196
 	 */
197
-	abstract public function get_status( $action_id );
197
+	abstract public function get_status($action_id);
198 198
 
199 199
 	/**
200 200
 	 * @param string $action_id
201 201
 	 * @return mixed
202 202
 	 */
203
-	abstract public function get_claim_id( $action_id );
203
+	abstract public function get_claim_id($action_id);
204 204
 
205 205
 	/**
206 206
 	 * @param string $claim_id
207 207
 	 * @return array
208 208
 	 */
209
-	abstract public function find_actions_by_claim_id( $claim_id );
209
+	abstract public function find_actions_by_claim_id($claim_id);
210 210
 
211 211
 	/**
212 212
 	 * @param string $comparison_operator
213 213
 	 * @return string
214 214
 	 */
215
-	protected function validate_sql_comparator( $comparison_operator ) {
216
-		if ( in_array( $comparison_operator, array('!=', '>', '>=', '<', '<=', '=') ) ) {
215
+	protected function validate_sql_comparator($comparison_operator) {
216
+		if (in_array($comparison_operator, array('!=', '>', '>=', '<', '<=', '='))) {
217 217
 			return $comparison_operator;
218 218
 		}
219 219
 		return '=';
@@ -226,14 +226,14 @@  discard block
 block discarded – undo
226 226
 	 * @param DateTime $scheduled_date (optional)
227 227
 	 * @return string
228 228
 	 */
229
-	protected function get_scheduled_date_string( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
229
+	protected function get_scheduled_date_string(ActionScheduler_Action $action, DateTime $scheduled_date = NULL) {
230 230
 		$next = null === $scheduled_date ? $action->get_schedule()->get_date() : $scheduled_date;
231
-		if ( ! $next ) {
231
+		if (!$next) {
232 232
 			return '0000-00-00 00:00:00';
233 233
 		}
234
-		$next->setTimezone( new DateTimeZone( 'UTC' ) );
234
+		$next->setTimezone(new DateTimeZone('UTC'));
235 235
 
236
-		return $next->format( 'Y-m-d H:i:s' );
236
+		return $next->format('Y-m-d H:i:s');
237 237
 	}
238 238
 
239 239
 	/**
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 	 * @param DateTime $scheduled_date (optional)
244 244
 	 * @return string
245 245
 	 */
246
-	protected function get_scheduled_date_string_local( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
246
+	protected function get_scheduled_date_string_local(ActionScheduler_Action $action, DateTime $scheduled_date = NULL) {
247 247
 		$next = null === $scheduled_date ? $action->get_schedule()->get_date() : $scheduled_date;
248
-		if ( ! $next ) {
248
+		if (!$next) {
249 249
 			return '0000-00-00 00:00:00';
250 250
 		}
251 251
 
252
-		ActionScheduler_TimezoneHelper::set_local_timezone( $next );
253
-		return $next->format( 'Y-m-d H:i:s' );
252
+		ActionScheduler_TimezoneHelper::set_local_timezone($next);
253
+		return $next->format('Y-m-d H:i:s');
254 254
 	}
255 255
 
256 256
 	/**
@@ -261,15 +261,15 @@  discard block
 block discarded – undo
261 261
 	 *
262 262
 	 * @throws ActionScheduler_InvalidActionException When the decoded arguments are invalid.
263 263
 	 */
264
-	protected function validate_args( $args, $action_id ) {
264
+	protected function validate_args($args, $action_id) {
265 265
 		// Ensure we have an array of args.
266
-		if ( ! is_array( $args ) ) {
267
-			throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id );
266
+		if (!is_array($args)) {
267
+			throw ActionScheduler_InvalidActionException::from_decoding_args($action_id);
268 268
 		}
269 269
 
270 270
 		// Validate JSON decoding if possible.
271
-		if ( function_exists( 'json_last_error' ) && JSON_ERROR_NONE !== json_last_error() ) {
272
-			throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id, $args );
271
+		if (function_exists('json_last_error') && JSON_ERROR_NONE !== json_last_error()) {
272
+			throw ActionScheduler_InvalidActionException::from_decoding_args($action_id, $args);
273 273
 		}
274 274
 	}
275 275
 
@@ -281,9 +281,9 @@  discard block
 block discarded – undo
281 281
 	 *
282 282
 	 * @throws ActionScheduler_InvalidActionException When the schedule is invalid.
283 283
 	 */
284
-	protected function validate_schedule( $schedule, $action_id ) {
285
-		if ( empty( $schedule ) || ! is_a( $schedule, 'ActionScheduler_Schedule' ) ) {
286
-			throw ActionScheduler_InvalidActionException::from_schedule( $action_id, $schedule );
284
+	protected function validate_schedule($schedule, $action_id) {
285
+		if (empty($schedule) || !is_a($schedule, 'ActionScheduler_Schedule')) {
286
+			throw ActionScheduler_InvalidActionException::from_schedule($action_id, $schedule);
287 287
 		}
288 288
 	}
289 289
 
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
 	 * @param  ActionScheduler_Action $action Action to be validated.
297 297
 	 * @throws InvalidArgumentException When json encoded args is too long.
298 298
 	 */
299
-	protected function validate_action( ActionScheduler_Action $action ) {
300
-		if ( strlen( json_encode( $action->get_args() ) ) > static::$max_args_length ) {
301
-			throw new InvalidArgumentException( sprintf( __( 'ActionScheduler_Action::$args too long. To ensure the args column can be indexed, action args should not be more than %d characters when encoded as JSON.', 'woocommerce' ), static::$max_args_length ) );
299
+	protected function validate_action(ActionScheduler_Action $action) {
300
+		if (strlen(json_encode($action->get_args())) > static::$max_args_length) {
301
+			throw new InvalidArgumentException(sprintf(__('ActionScheduler_Action::$args too long. To ensure the args column can be indexed, action args should not be more than %d characters when encoded as JSON.', 'woocommerce'), static::$max_args_length));
302 302
 		}
303 303
 	}
304 304
 
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
 	 *
312 312
 	 * @return void
313 313
 	 */
314
-	public function cancel_actions_by_hook( $hook ) {
314
+	public function cancel_actions_by_hook($hook) {
315 315
 		$action_ids = true;
316
-		while ( ! empty( $action_ids ) ) {
316
+		while (!empty($action_ids)) {
317 317
 			$action_ids = $this->query_actions(
318 318
 				array(
319 319
 					'hook'     => $hook,
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 				)
324 324
 			);
325 325
 
326
-			$this->bulk_cancel_actions( $action_ids );
326
+			$this->bulk_cancel_actions($action_ids);
327 327
 		}
328 328
 	}
329 329
 
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
 	 *
337 337
 	 * @return void
338 338
 	 */
339
-	public function cancel_actions_by_group( $group ) {
339
+	public function cancel_actions_by_group($group) {
340 340
 		$action_ids = true;
341
-		while ( ! empty( $action_ids ) ) {
341
+		while (!empty($action_ids)) {
342 342
 			$action_ids = $this->query_actions(
343 343
 				array(
344 344
 					'group'    => $group,
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 				)
349 349
 			);
350 350
 
351
-			$this->bulk_cancel_actions( $action_ids );
351
+			$this->bulk_cancel_actions($action_ids);
352 352
 		}
353 353
 	}
354 354
 
@@ -361,12 +361,12 @@  discard block
 block discarded – undo
361 361
 	 *
362 362
 	 * @return void
363 363
 	 */
364
-	private function bulk_cancel_actions( $action_ids ) {
365
-		foreach ( $action_ids as $action_id ) {
366
-			$this->cancel_action( $action_id );
364
+	private function bulk_cancel_actions($action_ids) {
365
+		foreach ($action_ids as $action_id) {
366
+			$this->cancel_action($action_id);
367 367
 		}
368 368
 
369
-		do_action( 'action_scheduler_bulk_cancel_actions', $action_ids );
369
+		do_action('action_scheduler_bulk_cancel_actions', $action_ids);
370 370
 	}
371 371
 
372 372
 	/**
@@ -374,11 +374,11 @@  discard block
 block discarded – undo
374 374
 	 */
375 375
 	public function get_status_labels() {
376 376
 		return array(
377
-			self::STATUS_COMPLETE => __( 'Complete', 'woocommerce' ),
378
-			self::STATUS_PENDING  => __( 'Pending', 'woocommerce' ),
379
-			self::STATUS_RUNNING  => __( 'In-progress', 'woocommerce' ),
380
-			self::STATUS_FAILED   => __( 'Failed', 'woocommerce' ),
381
-			self::STATUS_CANCELED => __( 'Canceled', 'woocommerce' ),
377
+			self::STATUS_COMPLETE => __('Complete', 'woocommerce'),
378
+			self::STATUS_PENDING  => __('Pending', 'woocommerce'),
379
+			self::STATUS_RUNNING  => __('In-progress', 'woocommerce'),
380
+			self::STATUS_FAILED   => __('Failed', 'woocommerce'),
381
+			self::STATUS_CANCELED => __('Canceled', 'woocommerce'),
382 382
 		);
383 383
 	}
384 384
 
@@ -390,13 +390,13 @@  discard block
 block discarded – undo
390 390
 	 * @return string
391 391
 	 */
392 392
 	public function has_pending_actions_due() {
393
-		$pending_actions = $this->query_actions( array(
393
+		$pending_actions = $this->query_actions(array(
394 394
 			'date'    => as_get_datetime_object(),
395 395
 			'status'  => ActionScheduler_Store::STATUS_PENDING,
396 396
 			'orderby' => 'none',
397
-		) );
397
+		));
398 398
 
399
-		return ! empty( $pending_actions );
399
+		return !empty($pending_actions);
400 400
 	}
401 401
 
402 402
 	/**
@@ -407,14 +407,14 @@  discard block
 block discarded – undo
407 407
 	/**
408 408
 	 * Callable function to mark an action as migrated optionally overridden in derived classes.
409 409
 	 */
410
-	public function mark_migrated( $action_id ) {}
410
+	public function mark_migrated($action_id) {}
411 411
 
412 412
 	/**
413 413
 	 * @return ActionScheduler_Store
414 414
 	 */
415 415
 	public static function instance() {
416
-		if ( empty( self::$store ) ) {
417
-			$class = apply_filters( 'action_scheduler_store_class', self::DEFAULT_CLASS );
416
+		if (empty(self::$store)) {
417
+			$class = apply_filters('action_scheduler_store_class', self::DEFAULT_CLASS);
418 418
 			self::$store = new $class();
419 419
 		}
420 420
 		return self::$store;
Please login to merge, or discard this patch.