Completed
Push — master ( ea7c62...226003 )
by J.D.
03:16
created
src/includes/constants.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@
 block discarded – undo
9 9
 
10 10
 global $wpdb;
11 11
 
12
-$wpdb->wordpoints_hook_hits = $wpdb->base_prefix . 'wordpoints_hook_hits';
13
-$wpdb->wordpoints_hook_hitmeta = $wpdb->base_prefix . 'wordpoints_hook_hitmeta';
14
-$wpdb->wordpoints_hook_periods = $wpdb->base_prefix . 'wordpoints_hook_periods';
12
+$wpdb->wordpoints_hook_hits = $wpdb->base_prefix.'wordpoints_hook_hits';
13
+$wpdb->wordpoints_hook_hitmeta = $wpdb->base_prefix.'wordpoints_hook_hitmeta';
14
+$wpdb->wordpoints_hook_periods = $wpdb->base_prefix.'wordpoints_hook_periods';
15 15
 
16 16
 // EOF
Please login to merge, or discard this patch.
src/includes/classes/db/query.php 1 patch
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
 	 *        @type array        $meta_query          See WP_Meta_Query.
215 215
 	 * }
216 216
 	 */
217
-	public function __construct( $args = array() ) {
218
-		$this->args = array_merge( $this->defaults, $args );
217
+	public function __construct($args = array()) {
218
+		$this->args = array_merge($this->defaults, $args);
219 219
 	}
220 220
 
221 221
 	/**
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @return mixed|null The query arg's value, or null if it isn't set.
229 229
 	 */
230
-	public function get_arg( $arg ) {
230
+	public function get_arg($arg) {
231 231
 
232
-		if ( isset( $this->args[ $arg ] ) ) {
233
-			return $this->args[ $arg ];
232
+		if (isset($this->args[$arg])) {
233
+			return $this->args[$arg];
234 234
 		} else {
235 235
 			return null;
236 236
 		}
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
 	 *
247 247
 	 * @param array $args A list of arguments to set and their values.
248 248
 	 */
249
-	public function set_args( array $args ) {
249
+	public function set_args(array $args) {
250 250
 
251
-		$this->args = array_merge( $this->args, $args );
251
+		$this->args = array_merge($this->args, $args);
252 252
 
253 253
 		$this->is_query_ready = false;
254 254
 	}
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 
270 270
 		global $wpdb;
271 271
 
272
-		$count = (int) $wpdb->get_var( $this->get_sql( 'SELECT COUNT' ) ); // WPCS: unprepared SQL, cache OK
272
+		$count = (int) $wpdb->get_var($this->get_sql('SELECT COUNT')); // WPCS: unprepared SQL, cache OK
273 273
 
274 274
 		return $count;
275 275
 	}
@@ -284,20 +284,20 @@  discard block
 block discarded – undo
284 284
 	 *
285 285
 	 * @return mixed The results of the query, or false on failure.
286 286
 	 */
287
-	public function get( $method = 'results' ) {
287
+	public function get($method = 'results') {
288 288
 
289 289
 		global $wpdb;
290 290
 
291
-		$methods = array( 'results', 'row', 'col', 'var' );
291
+		$methods = array('results', 'row', 'col', 'var');
292 292
 
293
-		if ( ! in_array( $method, $methods ) ) {
293
+		if ( ! in_array($method, $methods)) {
294 294
 
295
-			_doing_it_wrong( __METHOD__, esc_html( sprintf( 'WordPoints Debug Error: invalid get method %s, possible values are %s', $method, implode( ', ', $methods ) ) ), '1.0.0' );
295
+			_doing_it_wrong(__METHOD__, esc_html(sprintf('WordPoints Debug Error: invalid get method %s, possible values are %s', $method, implode(', ', $methods))), '1.0.0');
296 296
 
297 297
 			return false;
298 298
 		}
299 299
 
300
-		$result = $wpdb->{"get_{$method}"}( $this->get_sql() );
300
+		$result = $wpdb->{"get_{$method}"}($this->get_sql());
301 301
 
302 302
 		return $result;
303 303
 	}
@@ -317,11 +317,11 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @return string The SQL for the query.
319 319
 	 */
320
-	public function get_sql( $select_type = 'SELECT' ) {
320
+	public function get_sql($select_type = 'SELECT') {
321 321
 
322 322
 		$this->prepare_query();
323 323
 
324
-		$select = ( 'SELECT COUNT' === $select_type )
324
+		$select = ('SELECT COUNT' === $select_type)
325 325
 			? $this->select_count
326 326
 			: $this->select;
327 327
 
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
 	 *
350 350
 	 * @return string[] The valid columns.
351 351
 	 */
352
-	public function date_query_valid_columns_filter( $valid_columns ) {
352
+	public function date_query_valid_columns_filter($valid_columns) {
353 353
 
354 354
 		$valid_columns = array_merge(
355 355
 			$valid_columns
356 356
 			, array_keys(
357
-				wp_list_filter( $this->columns, array( 'is_date' => true ) )
357
+				wp_list_filter($this->columns, array('is_date' => true))
358 358
 			)
359 359
 		);
360 360
 
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 	 */
373 373
 	protected function prepare_query() {
374 374
 
375
-		if ( ! $this->is_query_ready ) {
375
+		if ( ! $this->is_query_ready) {
376 376
 
377 377
 			$this->prepare_select();
378 378
 			$this->prepare_where();
@@ -390,26 +390,26 @@  discard block
 block discarded – undo
390 390
 	 */
391 391
 	protected function prepare_select() {
392 392
 
393
-		$all_fields = array_keys( $this->columns );
393
+		$all_fields = array_keys($this->columns);
394 394
 		$fields = array();
395 395
 
396
-		if ( ! empty( $this->args['fields'] ) ) {
396
+		if ( ! empty($this->args['fields'])) {
397 397
 
398 398
 			$fields = (array) $this->args['fields'];
399
-			$diff   = array_diff( $fields, $all_fields );
400
-			$fields = array_intersect( $all_fields, $fields );
399
+			$diff   = array_diff($fields, $all_fields);
400
+			$fields = array_intersect($all_fields, $fields);
401 401
 
402
-			if ( ! empty( $diff ) ) {
403
-				_doing_it_wrong( __METHOD__, esc_html( 'WordPoints Debug Error: invalid field(s) "' . implode( '", "', $diff ) . '" given' ), '1.0.0' );
402
+			if ( ! empty($diff)) {
403
+				_doing_it_wrong(__METHOD__, esc_html('WordPoints Debug Error: invalid field(s) "'.implode('", "', $diff).'" given'), '1.0.0');
404 404
 			}
405 405
 		}
406 406
 
407 407
 		// Pull all fields by default.
408
-		if ( empty( $fields ) ) {
408
+		if (empty($fields)) {
409 409
 			$fields = $all_fields;
410 410
 		}
411 411
 
412
-		$fields = implode( ', ', array_map( 'wordpoints_escape_mysql_identifier', $fields ) );
412
+		$fields = implode(', ', array_map('wordpoints_escape_mysql_identifier', $fields));
413 413
 
414 414
 		$this->select = "SELECT {$fields}";
415 415
 	}
@@ -424,13 +424,13 @@  discard block
 block discarded – undo
424 424
 	 *
425 425
 	 * @return mixed The validated value, or false if invalid.
426 426
 	 */
427
-	protected function validate_value( $value, $validators ) {
427
+	protected function validate_value($value, $validators) {
428 428
 
429
-		foreach ( $validators as $validator ) {
429
+		foreach ($validators as $validator) {
430 430
 
431
-			$value = call_user_func_array( $validator, array( &$value ) );
431
+			$value = call_user_func_array($validator, array(&$value));
432 432
 
433
-			if ( false === $value ) {
433
+			if (false === $value) {
434 434
 				break;
435 435
 			}
436 436
 		}
@@ -448,14 +448,14 @@  discard block
 block discarded – undo
448 448
 	 *
449 449
 	 * @return array The validated values, with any invalid ones removed.
450 450
 	 */
451
-	protected function validate_values( $values, $validators ) {
451
+	protected function validate_values($values, $validators) {
452 452
 
453
-		foreach ( $values as $index => $value ) {
453
+		foreach ($values as $index => $value) {
454 454
 
455
-			$value = $this->validate_value( $value, $validators );
455
+			$value = $this->validate_value($value, $validators);
456 456
 
457
-			if ( false === $value ) {
458
-				unset( $values[ $index ] );
457
+			if (false === $value) {
458
+				unset($values[$index]);
459 459
 			}
460 460
 		}
461 461
 
@@ -474,9 +474,9 @@  discard block
 block discarded – undo
474 474
 	 *
475 475
 	 * @return int|false The validated value or false.
476 476
 	 */
477
-	protected function validate_unsigned_column( $value ) {
477
+	protected function validate_unsigned_column($value) {
478 478
 
479
-		if ( false !== wordpoints_int( $value ) && $value >= 0 ) {
479
+		if (false !== wordpoints_int($value) && $value >= 0) {
480 480
 			return $value;
481 481
 		}
482 482
 
@@ -492,14 +492,14 @@  discard block
 block discarded – undo
492 492
 	 *
493 493
 	 * @return callable[] The validation functions.
494 494
 	 */
495
-	protected function get_validators_for_column( $data ) {
495
+	protected function get_validators_for_column($data) {
496 496
 
497 497
 		$validators = array();
498 498
 
499 499
 		// Default validators for integer columns.
500
-		if ( '%d' === $data['format'] ) {
501
-			if ( ! empty( $data['unsigned'] ) ) {
502
-				$validators[] = array( $this, 'validate_unsigned_column' );
500
+		if ('%d' === $data['format']) {
501
+			if ( ! empty($data['unsigned'])) {
502
+				$validators[] = array($this, 'validate_unsigned_column');
503 503
 			} else {
504 504
 				$validators[] = 'wordpoints_int';
505 505
 			}
@@ -516,15 +516,15 @@  discard block
 block discarded – undo
516 516
 	 * @param string $column The column name.
517 517
 	 * @param array  $data   The column data.
518 518
 	 */
519
-	protected function prepare_column_where( $column, $data ) {
519
+	protected function prepare_column_where($column, $data) {
520 520
 
521 521
 		// If a single value has been supplied for the column, it takes precedence.
522
-		if ( isset( $this->args[ $column ] ) ) {
523
-			$this->prepare_column( $column, $data );
524
-		} elseif ( isset( $this->args[ "{$column}__in" ] ) ) {
525
-			$this->prepare_column__in( $column, $data );
526
-		} elseif ( isset( $this->args[ "{$column}__not_in" ] ) ) {
527
-			$this->prepare_column__in( $column, $data, 'NOT IN' );
522
+		if (isset($this->args[$column])) {
523
+			$this->prepare_column($column, $data);
524
+		} elseif (isset($this->args["{$column}__in"])) {
525
+			$this->prepare_column__in($column, $data);
526
+		} elseif (isset($this->args["{$column}__not_in"])) {
527
+			$this->prepare_column__in($column, $data, 'NOT IN');
528 528
 		}
529 529
 	}
530 530
 
@@ -536,29 +536,29 @@  discard block
 block discarded – undo
536 536
 	 * @param string $column The name of the column
537 537
 	 * @param array  $data   The column data.
538 538
 	 */
539
-	protected function prepare_column( $column, $data ) {
539
+	protected function prepare_column($column, $data) {
540 540
 
541 541
 		global $wpdb;
542 542
 
543 543
 		if (
544
-			isset( $data['values'] )
545
-			&& ! in_array( $this->args[ $column ], $data['values'], true )
544
+			isset($data['values'])
545
+			&& ! in_array($this->args[$column], $data['values'], true)
546 546
 		) {
547 547
 			return;
548 548
 		}
549 549
 
550 550
 		$value = $this->validate_value(
551
-			$this->args[ $column ]
552
-			, $this->get_validators_for_column( $data )
551
+			$this->args[$column]
552
+			, $this->get_validators_for_column($data)
553 553
 		);
554 554
 
555
-		if ( false === $value ) {
555
+		if (false === $value) {
556 556
 			return;
557 557
 		}
558 558
 
559
-		$compare = $this->get_comparator_for_column( $column, $data );
559
+		$compare = $this->get_comparator_for_column($column, $data);
560 560
 
561
-		$column = wordpoints_escape_mysql_identifier( $column );
561
+		$column = wordpoints_escape_mysql_identifier($column);
562 562
 
563 563
 		$this->wheres[] = $wpdb->prepare( // WPCS: unprepared SQL OK.
564 564
 			"{$column} {$compare} {$data['format']}"
@@ -576,23 +576,23 @@  discard block
 block discarded – undo
576 576
 	 *
577 577
 	 * @return string The comparator for the column.
578 578
 	 */
579
-	protected function get_comparator_for_column( $column, $data ) {
579
+	protected function get_comparator_for_column($column, $data) {
580 580
 
581
-		$comparisons = array( '=', '<', '>', '<>', '!=', '<=', '>=' );
581
+		$comparisons = array('=', '<', '>', '<>', '!=', '<=', '>=');
582 582
 
583 583
 		// MySQL doesn't support LIKE and NOT LIKE for int columns.
584 584
 		// See http://stackoverflow.com/q/8422455/1924128
585
-		if ( '%s' === $data['format'] ) {
586
-			$comparisons = array_merge( $comparisons, array( 'LIKE', 'NOT LIKE' ) );
585
+		if ('%s' === $data['format']) {
586
+			$comparisons = array_merge($comparisons, array('LIKE', 'NOT LIKE'));
587 587
 		}
588 588
 
589 589
 		$comparator = '=';
590 590
 
591 591
 		if (
592
-			isset( $this->args[ "{$column}__compare" ] )
593
-			&& in_array( $this->args[ "{$column}__compare" ], $comparisons, true )
592
+			isset($this->args["{$column}__compare"])
593
+			&& in_array($this->args["{$column}__compare"], $comparisons, true)
594 594
 		) {
595
-			$comparator = $this->args[ "{$column}__compare" ];
595
+			$comparator = $this->args["{$column}__compare"];
596 596
 		}
597 597
 
598 598
 		return $comparator;
@@ -607,36 +607,36 @@  discard block
 block discarded – undo
607 607
 	 * @param array  $data   The column data.
608 608
 	 * @param string $type   The type of IN clause, IN or NOT IN.
609 609
 	 */
610
-	protected function prepare_column__in( $column, $data, $type = 'IN' ) {
610
+	protected function prepare_column__in($column, $data, $type = 'IN') {
611 611
 
612
-		$key = "{$column}__" . strtolower( str_replace( ' ', '_', $type ) );
612
+		$key = "{$column}__".strtolower(str_replace(' ', '_', $type));
613 613
 
614
-		if ( empty( $this->args[ $key ] ) || ! is_array( $this->args[ $key ] ) ) {
614
+		if (empty($this->args[$key]) || ! is_array($this->args[$key])) {
615 615
 			return;
616 616
 		}
617 617
 
618
-		$values = $this->args[ $key ];
618
+		$values = $this->args[$key];
619 619
 
620
-		if ( isset( $data['values'] ) ) {
621
-			$values = array_intersect( $values, $data['values'] );
620
+		if (isset($data['values'])) {
621
+			$values = array_intersect($values, $data['values']);
622 622
 		} else {
623 623
 			$values = $this->validate_values(
624 624
 				$values
625
-				, $this->get_validators_for_column( $data )
625
+				, $this->get_validators_for_column($data)
626 626
 			);
627 627
 		}
628 628
 
629
-		if ( empty( $values ) ) {
629
+		if (empty($values)) {
630 630
 			return;
631 631
 		}
632 632
 
633
-		$in = wordpoints_prepare__in( $values, $data['format'] );
633
+		$in = wordpoints_prepare__in($values, $data['format']);
634 634
 
635
-		if ( false === $in ) {
635
+		if (false === $in) {
636 636
 			return;
637 637
 		}
638 638
 
639
-		$column = wordpoints_escape_mysql_identifier( $column );
639
+		$column = wordpoints_escape_mysql_identifier($column);
640 640
 
641 641
 		$this->wheres[] = "{$column} {$type} ({$in})";
642 642
 	}
@@ -650,19 +650,19 @@  discard block
 block discarded – undo
650 650
 
651 651
 		$this->wheres = array();
652 652
 
653
-		foreach ( $this->columns as $column => $data ) {
653
+		foreach ($this->columns as $column => $data) {
654 654
 
655
-			if ( ! empty( $data['is_date'] ) ) {
656
-				$this->prepare_date_where( $column );
655
+			if ( ! empty($data['is_date'])) {
656
+				$this->prepare_date_where($column);
657 657
 			} else {
658
-				$this->prepare_column_where( $column, $data );
658
+				$this->prepare_column_where($column, $data);
659 659
 			}
660 660
 		}
661 661
 
662 662
 		$this->prepare_meta_where();
663 663
 
664
-		if ( ! empty( $this->wheres ) ) {
665
-			$this->where = 'WHERE ' . implode( ' AND ', $this->wheres ) . "\n";
664
+		if ( ! empty($this->wheres)) {
665
+			$this->where = 'WHERE '.implode(' AND ', $this->wheres)."\n";
666 666
 		}
667 667
 	}
668 668
 
@@ -675,32 +675,32 @@  discard block
 block discarded – undo
675 675
 
676 676
 		// MySQL doesn't allow for the offset without a limit, so if no limit is set
677 677
 		// we can ignore the start arg. See http://stackoverflow.com/a/271650/1924128
678
-		if ( ! isset( $this->args['limit'] ) ) {
678
+		if ( ! isset($this->args['limit'])) {
679 679
 			return;
680 680
 		}
681 681
 
682
-		foreach ( array( 'limit', 'start' ) as $key ) {
682
+		foreach (array('limit', 'start') as $key) {
683 683
 
684 684
 			// Save a backup of the arg value since wordpoints_int() is by reference.
685
-			$arg = $this->args[ $key ];
685
+			$arg = $this->args[$key];
686 686
 
687
-			if ( false === wordpoints_int( $this->args[ $key ] ) ) {
687
+			if (false === wordpoints_int($this->args[$key])) {
688 688
 
689 689
 				_doing_it_wrong(
690 690
 					__METHOD__
691 691
 					, sprintf(
692 692
 						"WordPoints Debug Error: '%s' must be a positive integer, %s given"
693
-						, esc_html( $key )
694
-						, esc_html( strval( $arg ) ? $arg : gettype( $arg ) )
693
+						, esc_html($key)
694
+						, esc_html(strval($arg) ? $arg : gettype($arg))
695 695
 					)
696 696
 					, '1.0.0'
697 697
 				);
698 698
 
699
-				$this->args[ $key ] = 0;
699
+				$this->args[$key] = 0;
700 700
 			}
701 701
 		}
702 702
 
703
-		if ( $this->args['limit'] > 0 && $this->args['start'] >= 0 ) {
703
+		if ($this->args['limit'] > 0 && $this->args['start'] >= 0) {
704 704
 			$this->limit = "LIMIT {$this->args['start']}, {$this->args['limit']}";
705 705
 		}
706 706
 	}
@@ -712,20 +712,20 @@  discard block
 block discarded – undo
712 712
 	 */
713 713
 	protected function prepare_order_by() {
714 714
 
715
-		if ( empty( $this->args['order_by'] ) ) {
715
+		if (empty($this->args['order_by'])) {
716 716
 			return;
717 717
 		}
718 718
 
719 719
 		$order    = $this->args['order'];
720 720
 		$order_by = $this->args['order_by'];
721 721
 
722
-		if ( ! in_array( $order, array( 'DESC', 'ASC' ) ) ) {
722
+		if ( ! in_array($order, array('DESC', 'ASC'))) {
723 723
 
724
-			_doing_it_wrong( __METHOD__, esc_html( "WordPoints Debug Error: invalid 'order' \"{$order}\", possible values are DESC and ASC" ), '1.0.0' );
724
+			_doing_it_wrong(__METHOD__, esc_html("WordPoints Debug Error: invalid 'order' \"{$order}\", possible values are DESC and ASC"), '1.0.0');
725 725
 			$order = 'DESC';
726 726
 		}
727 727
 
728
-		if ( 'meta_value' === $order_by ) {
728
+		if ('meta_value' === $order_by) {
729 729
 
730 730
 			global $wpdb;
731 731
 
@@ -733,9 +733,9 @@  discard block
 block discarded – undo
733 733
 				$wpdb->{"{$this->meta_type}meta"}
734 734
 			);
735 735
 
736
-			if ( isset( $this->args['meta_type'] ) ) {
736
+			if (isset($this->args['meta_type'])) {
737 737
 
738
-				$meta_type = $this->meta_query->get_cast_for_type( $this->args['meta_type'] );
738
+				$meta_type = $this->meta_query->get_cast_for_type($this->args['meta_type']);
739 739
 				$order_by  = "CAST({$meta_table_name}.meta_value AS {$meta_type})";
740 740
 
741 741
 			} else {
@@ -743,13 +743,13 @@  discard block
 block discarded – undo
743 743
 				$order_by = "{$meta_table_name}.meta_value";
744 744
 			}
745 745
 
746
-		} elseif ( isset( $this->columns[ $order_by ] ) ) {
746
+		} elseif (isset($this->columns[$order_by])) {
747 747
 
748
-			$order_by = wordpoints_escape_mysql_identifier( $order_by );
748
+			$order_by = wordpoints_escape_mysql_identifier($order_by);
749 749
 
750 750
 		} else {
751 751
 
752
-			_doing_it_wrong( __METHOD__, esc_html( "WordPoints Debug Error: invalid 'order_by' \"{$order_by}\", possible values are " . implode( ', ', array_keys( $this->columns ) ) ), '1.0.0' );
752
+			_doing_it_wrong(__METHOD__, esc_html("WordPoints Debug Error: invalid 'order_by' \"{$order_by}\", possible values are ".implode(', ', array_keys($this->columns))), '1.0.0');
753 753
 			return;
754 754
 		}
755 755
 
@@ -763,25 +763,25 @@  discard block
 block discarded – undo
763 763
 	 *
764 764
 	 * @param string $column The name of the column.
765 765
 	 */
766
-	protected function prepare_date_where( $column ) {
766
+	protected function prepare_date_where($column) {
767 767
 
768 768
 		if (
769
-			empty( $this->args[ "{$column}_query" ] )
770
-			|| ! is_array( $this->args[ "{$column}_query" ] )
769
+			empty($this->args["{$column}_query"])
770
+			|| ! is_array($this->args["{$column}_query"])
771 771
 		) {
772 772
 			return;
773 773
 		}
774 774
 
775
-		add_filter( 'date_query_valid_columns', array( $this, 'date_query_valid_columns_filter' ) );
775
+		add_filter('date_query_valid_columns', array($this, 'date_query_valid_columns_filter'));
776 776
 
777
-		$date_query = new WP_Date_Query( $this->args[ "{$column}_query" ], $column );
777
+		$date_query = new WP_Date_Query($this->args["{$column}_query"], $column);
778 778
 		$date_query = $date_query->get_sql();
779 779
 
780
-		if ( ! empty( $date_query ) ) {
781
-			$this->wheres[] = ltrim( $date_query, ' AND' );
780
+		if ( ! empty($date_query)) {
781
+			$this->wheres[] = ltrim($date_query, ' AND');
782 782
 		}
783 783
 
784
-		remove_filter( 'date_query_valid_columns', array( $this, 'date_query_valid_columns_filter' ) );
784
+		remove_filter('date_query_valid_columns', array($this, 'date_query_valid_columns_filter'));
785 785
 	}
786 786
 
787 787
 	/**
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 	 */
792 792
 	protected function prepare_meta_where() {
793 793
 
794
-		if ( empty( $this->meta_type ) ) {
794
+		if (empty($this->meta_type)) {
795 795
 			return;
796 796
 		}
797 797
 
@@ -806,12 +806,12 @@  discard block
 block discarded – undo
806 806
 			)
807 807
 		);
808 808
 
809
-		if ( empty( $meta_args ) ) {
809
+		if (empty($meta_args)) {
810 810
 			return;
811 811
 		}
812 812
 
813 813
 		$this->meta_query = new WP_Meta_Query();
814
-		$this->meta_query->parse_query_vars( $meta_args );
814
+		$this->meta_query->parse_query_vars($meta_args);
815 815
 
816 816
 		$meta_query = $this->meta_query->get_sql(
817 817
 			$this->meta_type
@@ -820,11 +820,11 @@  discard block
 block discarded – undo
820 820
 			, $this
821 821
 		);
822 822
 
823
-		if ( ! empty( $meta_query['where'] ) ) {
824
-			$this->wheres[] = ltrim( $meta_query['where'], ' AND' );
823
+		if ( ! empty($meta_query['where'])) {
824
+			$this->wheres[] = ltrim($meta_query['where'], ' AND');
825 825
 		}
826 826
 
827
-		$this->meta_join = $meta_query['join'] . "\n";
827
+		$this->meta_join = $meta_query['join']."\n";
828 828
 	}
829 829
 }
830 830
 
Please login to merge, or discard this patch.
src/admin/includes/classes/ajax/hooks.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 	) {
97 97
 
98 98
 		return 'wordpoints_create_hook_reaction|' . $reactor->get_slug()
99
-		       . '|' . wordpoints_hooks()->get_current_mode()
100
-		       . '|' . wp_json_encode( $reactor->reactions->get_context_id() );
99
+			   . '|' . wordpoints_hooks()->get_current_mode()
100
+			   . '|' . wp_json_encode( $reactor->reactions->get_context_id() );
101 101
 	}
102 102
 
103 103
 	/**
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		WordPoints_Hook_ReactionI $reaction
128 128
 	) {
129 129
 		return 'wordpoints_update_hook_reaction|'
130
-		       . wp_json_encode( $reaction->get_guid() );
130
+			   . wp_json_encode( $reaction->get_guid() );
131 131
 	}
132 132
 
133 133
 	/**
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		WordPoints_Hook_ReactionI $reaction
158 158
 	) {
159 159
 		return 'wordpoints_delete_hook_reaction|'
160
-		       . wp_json_encode( $reaction->get_guid() );
160
+			   . wp_json_encode( $reaction->get_guid() );
161 161
 	}
162 162
 
163 163
 	//
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @return array The hook reaction data extracted into an array.
54 54
 	 */
55
-	public static function prepare_hook_reaction( WordPoints_Hook_ReactionI $reaction ) {
55
+	public static function prepare_hook_reaction(WordPoints_Hook_ReactionI $reaction) {
56 56
 
57 57
 		return array_merge(
58 58
 			$reaction->get_all_meta()
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 				'id' => $reaction->ID,
61 61
 				'event' => $reaction->get_event_slug(),
62 62
 				'reactor' => $reaction->get_reactor_slug(),
63
-				'nonce' => self::get_update_nonce( $reaction ),
64
-				'delete_nonce' => self::get_delete_nonce( $reaction ),
63
+				'nonce' => self::get_update_nonce($reaction),
64
+				'delete_nonce' => self::get_delete_nonce($reaction),
65 65
 			)
66 66
 		);
67 67
 	}
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return string A nonce for creating a new reaction to this reactor.
78 78
 	 */
79
-	public static function get_create_nonce( WordPoints_Hook_Reactor $reactor ) {
79
+	public static function get_create_nonce(WordPoints_Hook_Reactor $reactor) {
80 80
 
81
-		return wp_create_nonce( self::get_create_nonce_action( $reactor ) );
81
+		return wp_create_nonce(self::get_create_nonce_action($reactor));
82 82
 	}
83 83
 
84 84
 	/**
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 		WordPoints_Hook_Reactor $reactor
96 96
 	) {
97 97
 
98
-		return 'wordpoints_create_hook_reaction|' . $reactor->get_slug()
99
-		       . '|' . wordpoints_hooks()->get_current_mode()
100
-		       . '|' . wp_json_encode( $reactor->reactions->get_context_id() );
98
+		return 'wordpoints_create_hook_reaction|'.$reactor->get_slug()
99
+		       . '|'.wordpoints_hooks()->get_current_mode()
100
+		       . '|'.wp_json_encode($reactor->reactions->get_context_id());
101 101
 	}
102 102
 
103 103
 	/**
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @return string A nonce for updating this reaction.
111 111
 	 */
112
-	public static function get_update_nonce( WordPoints_Hook_ReactionI $reaction ) {
112
+	public static function get_update_nonce(WordPoints_Hook_ReactionI $reaction) {
113 113
 
114
-		return wp_create_nonce( self::get_update_nonce_action( $reaction ) );
114
+		return wp_create_nonce(self::get_update_nonce_action($reaction));
115 115
 	}
116 116
 
117 117
 	/**
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		WordPoints_Hook_ReactionI $reaction
128 128
 	) {
129 129
 		return 'wordpoints_update_hook_reaction|'
130
-		       . wp_json_encode( $reaction->get_guid() );
130
+		       . wp_json_encode($reaction->get_guid());
131 131
 	}
132 132
 
133 133
 	/**
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @return string A nonce for deleting this reaction.
141 141
 	 */
142
-	public static function get_delete_nonce( WordPoints_Hook_ReactionI $reaction ) {
142
+	public static function get_delete_nonce(WordPoints_Hook_ReactionI $reaction) {
143 143
 
144
-		return wp_create_nonce( self::get_delete_nonce_action( $reaction ) );
144
+		return wp_create_nonce(self::get_delete_nonce_action($reaction));
145 145
 	}
146 146
 
147 147
 	/**
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		WordPoints_Hook_ReactionI $reaction
158 158
 	) {
159 159
 		return 'wordpoints_delete_hook_reaction|'
160
-		       . wp_json_encode( $reaction->get_guid() );
160
+		       . wp_json_encode($reaction->get_guid());
161 161
 	}
162 162
 
163 163
 	//
@@ -183,17 +183,17 @@  discard block
 block discarded – undo
183 183
 
184 184
 		add_action(
185 185
 			'wp_ajax_wordpoints_admin_create_hook_reaction'
186
-			, array( $this, 'create_hook_reaction' )
186
+			, array($this, 'create_hook_reaction')
187 187
 		);
188 188
 
189 189
 		add_action(
190 190
 			'wp_ajax_wordpoints_admin_update_hook_reaction'
191
-			, array( $this, 'update_hook_reaction' )
191
+			, array($this, 'update_hook_reaction')
192 192
 		);
193 193
 
194 194
 		add_action(
195 195
 			'wp_ajax_wordpoints_admin_delete_hook_reaction'
196
-			, array( $this, 'delete_hook_reaction' )
196
+			, array($this, 'delete_hook_reaction')
197 197
 		);
198 198
 	}
199 199
 
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 
209 209
 		$reactor = $this->get_reactor();
210 210
 
211
-		$this->verify_request( $this->get_create_nonce_action( $reactor ) );
211
+		$this->verify_request($this->get_create_nonce_action($reactor));
212 212
 
213
-		$reaction = $reactor->reactions->create_reaction( $this->get_data() );
213
+		$reaction = $reactor->reactions->create_reaction($this->get_data());
214 214
 
215
-		$this->send_json_result( $reaction, 'create' );
215
+		$this->send_json_result($reaction, 'create');
216 216
 	}
217 217
 
218 218
 	/**
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 		$reactor  = $this->get_reactor();
228 228
 		$reaction = $this->get_reaction();
229 229
 
230
-		$this->verify_request( $this->get_update_nonce_action( $reaction ) );
230
+		$this->verify_request($this->get_update_nonce_action($reaction));
231 231
 
232 232
 		$reaction = $reactor->reactions->update_reaction(
233 233
 			$reaction->ID
234 234
 			, $this->get_data()
235 235
 		);
236 236
 
237
-		$this->send_json_result( $reaction, 'update' );
237
+		$this->send_json_result($reaction, 'update');
238 238
 	}
239 239
 
240 240
 	/**
@@ -249,12 +249,12 @@  discard block
 block discarded – undo
249 249
 		$reactor  = $this->get_reactor();
250 250
 		$reaction = $this->get_reaction();
251 251
 
252
-		$this->verify_request( $this->get_delete_nonce_action( $reaction ) );
252
+		$this->verify_request($this->get_delete_nonce_action($reaction));
253 253
 
254
-		$result = $reactor->reactions->delete_reaction( $reaction->ID );
254
+		$result = $reactor->reactions->delete_reaction($reaction->ID);
255 255
 
256
-		if ( ! $result ) {
257
-			wp_send_json_error( array( 'message' => __( 'There was an error deleting the reaction. Please try again.', 'wordpoints' ) ) );
256
+		if ( ! $result) {
257
+			wp_send_json_error(array('message' => __('There was an error deleting the reaction. Please try again.', 'wordpoints')));
258 258
 		}
259 259
 
260 260
 		wp_send_json_success();
@@ -275,11 +275,11 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 * @param string $debug_context Context sent with the message (for debugging).
277 277
 	 */
278
-	private function unexpected_error( $debug_context ) {
278
+	private function unexpected_error($debug_context) {
279 279
 
280 280
 		wp_send_json_error(
281 281
 			array(
282
-				'message' => __( 'There was an unexpected error. Try reloading the page.', 'wordpoints' ),
282
+				'message' => __('There was an unexpected error. Try reloading the page.', 'wordpoints'),
283 283
 				'debug'   => $debug_context,
284 284
 			)
285 285
 		);
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 */
296 296
 	private function verify_user_can() {
297 297
 
298
-		if ( ! current_user_can( 'manage_options' ) ) {
299
-			wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action. Maybe you have been logged out?', 'wordpoints' ) ) );
298
+		if ( ! current_user_can('manage_options')) {
299
+			wp_send_json_error(array('message' => __('You do not have permission to perform this action. Maybe you have been logged out?', 'wordpoints')));
300 300
 		}
301 301
 	}
302 302
 
@@ -309,14 +309,14 @@  discard block
 block discarded – undo
309 309
 	 *
310 310
 	 * @param string $action The action the nonce should be for.
311 311
 	 */
312
-	private function verify_request( $action ) {
312
+	private function verify_request($action) {
313 313
 
314 314
 		if (
315
-			empty( $_POST['nonce'] )
316
-			|| ! wordpoints_verify_nonce( 'nonce', $action, null, 'post' )
315
+			empty($_POST['nonce'])
316
+			|| ! wordpoints_verify_nonce('nonce', $action, null, 'post')
317 317
 		) {
318 318
 			wp_send_json_error(
319
-				array( 'message' => __( 'Your security token for this action has expired. Refresh the page and try again.', 'wordpoints' ) )
319
+				array('message' => __('Your security token for this action has expired. Refresh the page and try again.', 'wordpoints'))
320 320
 			);
321 321
 		}
322 322
 	}
@@ -330,16 +330,16 @@  discard block
 block discarded – undo
330 330
 	 */
331 331
 	protected function get_reactor() {
332 332
 
333
-		if ( ! isset( $_POST['reactor'] ) ) { // WPCS: CSRF OK.
334
-			$this->unexpected_error( 'reactor' );
333
+		if ( ! isset($_POST['reactor'])) { // WPCS: CSRF OK.
334
+			$this->unexpected_error('reactor');
335 335
 		}
336 336
 
337
-		$reactor_slug = sanitize_key( $_POST['reactor'] ); // WPCS: CSRF OK.
337
+		$reactor_slug = sanitize_key($_POST['reactor']); // WPCS: CSRF OK.
338 338
 
339
-		$reactor = wordpoints_hooks()->reactors->get( $reactor_slug );
339
+		$reactor = wordpoints_hooks()->reactors->get($reactor_slug);
340 340
 
341
-		if ( ! $reactor instanceof WordPoints_Hook_Reactor ) {
342
-			$this->unexpected_error( 'reactor_invalid' );
341
+		if ( ! $reactor instanceof WordPoints_Hook_Reactor) {
342
+			$this->unexpected_error('reactor_invalid');
343 343
 		}
344 344
 
345 345
 		$this->reactor_slug = $reactor_slug;
@@ -357,16 +357,16 @@  discard block
 block discarded – undo
357 357
 	 */
358 358
 	protected function get_reaction() {
359 359
 
360
-		if ( ! isset( $_POST['id'] ) ) { // WPCS: CSRF OK.
361
-			$this->unexpected_error( 'id' );
360
+		if ( ! isset($_POST['id'])) { // WPCS: CSRF OK.
361
+			$this->unexpected_error('id');
362 362
 		}
363 363
 
364 364
 		$reaction = $this->reactor->reactions->get_reaction(
365
-			wordpoints_int( $_POST['id'] ) // WPCS: CSRF OK.
365
+			wordpoints_int($_POST['id']) // WPCS: CSRF OK.
366 366
 		);
367 367
 
368
-		if ( ! $reaction ) {
369
-			wp_send_json_error( array( 'message' => __( 'The reaction ID passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints' ) ) );
368
+		if ( ! $reaction) {
369
+			wp_send_json_error(array('message' => __('The reaction ID passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints')));
370 370
 		}
371 371
 
372 372
 		return $reaction;
@@ -381,9 +381,9 @@  discard block
 block discarded – undo
381 381
 	 */
382 382
 	protected function get_data() {
383 383
 
384
-		$data = wp_unslash( $_POST ); // WPCS: CSRF OK.
384
+		$data = wp_unslash($_POST); // WPCS: CSRF OK.
385 385
 
386
-		unset( $data['id'], $data['action'], $data['nonce'], $data['reactor'] );
386
+		unset($data['id'], $data['action'], $data['nonce'], $data['reactor']);
387 387
 
388 388
 		return $data;
389 389
 	}
@@ -396,30 +396,30 @@  discard block
 block discarded – undo
396 396
 	 * @param mixed  $result The result of the action.
397 397
 	 * @param string $action The action being performed: 'create' or 'update'.
398 398
 	 */
399
-	private function send_json_result( $result, $action ) {
399
+	private function send_json_result($result, $action) {
400 400
 
401
-		if ( ! $result ) {
401
+		if ( ! $result) {
402 402
 
403
-			if ( 'create' === $action ) {
404
-				$message = __( 'There was an error adding the reaction. Please try again.', 'wordpoints' );
403
+			if ('create' === $action) {
404
+				$message = __('There was an error adding the reaction. Please try again.', 'wordpoints');
405 405
 			} else {
406
-				$message = __( 'There was an error updating the reaction. Please try again.', 'wordpoints' );
406
+				$message = __('There was an error updating the reaction. Please try again.', 'wordpoints');
407 407
 			}
408 408
 
409
-			wp_send_json_error( array( 'message' => $message ) );
409
+			wp_send_json_error(array('message' => $message));
410 410
 
411
-		} elseif ( $result instanceof WordPoints_Hook_Reaction_Validator ) {
411
+		} elseif ($result instanceof WordPoints_Hook_Reaction_Validator) {
412 412
 
413
-			wp_send_json_error( array( 'errors' => $result->get_errors() ) );
413
+			wp_send_json_error(array('errors' => $result->get_errors()));
414 414
 		}
415 415
 
416 416
 		$data = null;
417 417
 
418
-		if ( 'create' === $action ) {
419
-			$data = self::prepare_hook_reaction( $result );
418
+		if ('create' === $action) {
419
+			$data = self::prepare_hook_reaction($result);
420 420
 		}
421 421
 
422
-		wp_send_json_success( $data );
422
+		wp_send_json_success($data);
423 423
 	}
424 424
 }
425 425
 
Please login to merge, or discard this patch.
src/includes/functions.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
  *
34 34
  * @param WordPoints_Class_Registry_Persistent $reactors The reactors registry.
35 35
  */
36
-function wordpoints_hook_reactors_init( $reactors ) {
36
+function wordpoints_hook_reactors_init($reactors) {
37 37
 
38
-	$reactors->register( 'points', 'WordPoints_Hook_Reactor_Points' );
38
+	$reactors->register('points', 'WordPoints_Hook_Reactor_Points');
39 39
 }
40 40
 
41 41
 /**
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
  *
48 48
  * @param WordPoints_Class_Registry_Children $reaction_stores The store registry.
49 49
  */
50
-function wordpoints_hook_reaction_stores_init( $reaction_stores ) {
50
+function wordpoints_hook_reaction_stores_init($reaction_stores) {
51 51
 
52 52
 	$reaction_stores->register(
53 53
 		'points'
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 		, 'WordPoints_Hook_Reaction_Store_Options'
56 56
 	);
57 57
 
58
-	if ( is_wordpoints_network_active() ) {
58
+	if (is_wordpoints_network_active()) {
59 59
 		$reaction_stores->register(
60 60
 			'points'
61 61
 			, 'network'
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
  *
74 74
  * @param WordPoints_Class_Registry_Persistent $extensions The extension registry.
75 75
  */
76
-function wordpoints_hook_extension_init( $extensions ) {
76
+function wordpoints_hook_extension_init($extensions) {
77 77
 
78
-	$extensions->register( 'blocker', 'WordPoints_Hook_Extension_Blocker' );
79
-	$extensions->register( 'conditions', 'WordPoints_Hook_Extension_Conditions' );
80
-	$extensions->register( 'periods', 'WordPoints_Hook_Extension_Periods' );
78
+	$extensions->register('blocker', 'WordPoints_Hook_Extension_Blocker');
79
+	$extensions->register('conditions', 'WordPoints_Hook_Extension_Conditions');
80
+	$extensions->register('periods', 'WordPoints_Hook_Extension_Periods');
81 81
 }
82 82
 
83 83
 /**
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
  *
90 90
  * @param WordPoints_Class_Registry_Children $conditions The conditions registry.
91 91
  */
92
-function wordpoints_hook_conditions_init( $conditions ) {
92
+function wordpoints_hook_conditions_init($conditions) {
93 93
 
94 94
 	$conditions->register(
95 95
 		'text'
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
  *
126 126
  * @param WordPoints_Hook_Actions $actions The action registry.
127 127
  */
128
-function wordpoints_hook_actions_init( $actions ) {
128
+function wordpoints_hook_actions_init($actions) {
129 129
 
130 130
 	$actions->register(
131 131
 		'comment_approve'
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 		, array(
134 134
 			'action' => 'transition_comment_status',
135 135
 			'data'   => array(
136
-				'arg_index'    => array( 'comment' => 2 ),
137
-				'requirements' => array( 0 => 'approved' ),
136
+				'arg_index'    => array('comment' => 2),
137
+				'requirements' => array(0 => 'approved'),
138 138
 			),
139 139
 		)
140 140
 	);
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		, array(
146 146
 			'action' => 'wp_insert_comment',
147 147
 			'data'   => array(
148
-				'arg_index' => array( 'comment' => 1 ),
148
+				'arg_index' => array('comment' => 1),
149 149
 			),
150 150
 		)
151 151
 	);
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 		, array(
157 157
 			'action' => 'transition_comment_status',
158 158
 			'data'   => array(
159
-				'arg_index' => array( 'comment' => 2 ),
160
-				'requirements' => array( 1 => 'approved' ),
159
+				'arg_index' => array('comment' => 2),
160
+				'requirements' => array(1 => 'approved'),
161 161
 			),
162 162
 		)
163 163
 	);
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 		, array(
170 170
 			'action' => 'transition_post_status',
171 171
 			'data'   => array(
172
-				'arg_index' => array( 'post' => 2 ),
173
-				'requirements' => array( 0 => 'publish' ),
172
+				'arg_index' => array('post' => 2),
173
+				'requirements' => array(0 => 'publish'),
174 174
 			),
175 175
 		)
176 176
 	);
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
 		, array(
182 182
 			'action' => 'transition_post_status',
183 183
 			'data'   => array(
184
-				'arg_index' => array( 'post' => 2 ),
185
-				'requirements' => array( 1 => 'publish' ),
184
+				'arg_index' => array('post' => 2),
185
+				'requirements' => array(1 => 'publish'),
186 186
 			),
187 187
 		)
188 188
 	);
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		, array(
194 194
 			'action' => 'add_attachment',
195 195
 			'data'   => array(
196
-				'arg_index' => array( 'post\attachment' => 0 ),
196
+				'arg_index' => array('post\attachment' => 0),
197 197
 			),
198 198
 		)
199 199
 	);
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 		, array(
205 205
 			'action' => 'delete_post',
206 206
 			'data'   => array(
207
-				'arg_index' => array( 'post' => 0 ),
207
+				'arg_index' => array('post' => 0),
208 208
 			),
209 209
 		)
210 210
 	);
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 		, array(
216 216
 			'action' => 'user_register',
217 217
 			'data'   => array(
218
-				'arg_index' => array( 'user' => 0 ),
218
+				'arg_index' => array('user' => 0),
219 219
 			),
220 220
 		)
221 221
 	);
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		, array(
227 227
 			'action' => is_multisite() ? 'wpmu_delete_user' : 'delete_user',
228 228
 			'data'   => array(
229
-				'arg_index' => array( 'user' => 0 ),
229
+				'arg_index' => array('user' => 0),
230 230
 			),
231 231
 		)
232 232
 	);
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
  *
250 250
  * @param WordPoints_Hook_Events $events The event registry.
251 251
  */
252
-function wordpoints_hook_events_init( $events ) {
252
+function wordpoints_hook_events_init($events) {
253 253
 
254 254
 	$events->register(
255 255
 		'user_register'
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	);
280 280
 
281 281
 	// Register events for all of the public post types.
282
-	$post_types = get_post_types( array( 'public' => true ) );
282
+	$post_types = get_post_types(array('public' => true));
283 283
 
284 284
 	/**
285 285
 	 * Filter which post types to register hook events for.
@@ -288,20 +288,20 @@  discard block
 block discarded – undo
288 288
 	 *
289 289
 	 * @param string[] The post type slugs ("names").
290 290
 	 */
291
-	$post_types = apply_filters( 'wordpoints_register_hook_events_for_post_types', $post_types );
291
+	$post_types = apply_filters('wordpoints_register_hook_events_for_post_types', $post_types);
292 292
 
293
-	foreach ( $post_types as $slug ) {
294
-		wordpoints_register_post_type_hook_events( $slug );
293
+	foreach ($post_types as $slug) {
294
+		wordpoints_register_post_type_hook_events($slug);
295 295
 	}
296 296
 
297
-	if ( is_multisite() ) {
297
+	if (is_multisite()) {
298 298
 
299 299
 		$event_slugs = array(
300 300
 			'user_visit',
301 301
 			'user_register',
302 302
 		);
303 303
 
304
-		foreach ( $event_slugs as $event_slug ) {
304
+		foreach ($event_slugs as $event_slug) {
305 305
 			// TODO network hooks
306 306
 			$events->args->register(
307 307
 				$event_slug
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
  *
322 322
  * @param WordPoints_App_Registry $entities The entities app.
323 323
  */
324
-function wordpoints_entities_app_init( $entities ) {
324
+function wordpoints_entities_app_init($entities) {
325 325
 
326
-	$entities->sub_apps->register( 'children', 'WordPoints_Class_Registry_Children' );
327
-	$entities->sub_apps->register( 'contexts', 'WordPoints_Class_Registry' );
326
+	$entities->sub_apps->register('children', 'WordPoints_Class_Registry_Children');
327
+	$entities->sub_apps->register('contexts', 'WordPoints_Class_Registry');
328 328
 }
329 329
 
330 330
 /**
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
  *
337 337
  * @param WordPoints_Class_Registry $contexts The entity context registry.
338 338
  */
339
-function wordpoints_entity_contexts_init( $contexts ) {
339
+function wordpoints_entity_contexts_init($contexts) {
340 340
 
341
-	$contexts->register( 'network', 'WordPoints_Entity_Context_Network' );
342
-	$contexts->register( 'site', 'WordPoints_Entity_Context_Site' );
341
+	$contexts->register('network', 'WordPoints_Entity_Context_Network');
342
+	$contexts->register('site', 'WordPoints_Entity_Context_Site');
343 343
 }
344 344
 
345 345
 /**
@@ -351,18 +351,18 @@  discard block
 block discarded – undo
351 351
  *
352 352
  * @param WordPoints_App_Registry $entities The entities app.
353 353
  */
354
-function wordpoints_entities_init( $entities ) {
354
+function wordpoints_entities_init($entities) {
355 355
 
356 356
 	$children = $entities->children;
357 357
 
358
-	$entities->register( 'user', 'WordPoints_Entity_User' );
359
-	$children->register( 'user', 'roles', 'WordPoints_Entity_User_Roles' );
358
+	$entities->register('user', 'WordPoints_Entity_User');
359
+	$children->register('user', 'roles', 'WordPoints_Entity_User_Roles');
360 360
 
361
-	$entities->register( 'user_role', 'WordPoints_Entity_User_Role' );
362
-	$children->register( 'user_role', 'name', 'WordPoints_Entity_User_Role_Name' );
361
+	$entities->register('user_role', 'WordPoints_Entity_User_Role');
362
+	$children->register('user_role', 'name', 'WordPoints_Entity_User_Role_Name');
363 363
 
364 364
 	// Register entities for all of the public post types.
365
-	$post_types = get_post_types( array( 'public' => true ) );
365
+	$post_types = get_post_types(array('public' => true));
366 366
 
367 367
 	/**
368 368
 	 * Filter which post types to register entities for.
@@ -371,14 +371,14 @@  discard block
 block discarded – undo
371 371
 	 *
372 372
 	 * @param string[] The post type slugs ("names").
373 373
 	 */
374
-	$post_types = apply_filters( 'wordpoints_register_entities_for_post_types', $post_types );
374
+	$post_types = apply_filters('wordpoints_register_entities_for_post_types', $post_types);
375 375
 
376
-	foreach ( $post_types as $slug ) {
377
-		wordpoints_register_post_type_entities( $slug );
376
+	foreach ($post_types as $slug) {
377
+		wordpoints_register_post_type_entities($slug);
378 378
 	}
379 379
 
380 380
 	// Register entities for all of the public taxonomies.
381
-	$taxonomies = get_taxonomies( array( 'public' => true ) );
381
+	$taxonomies = get_taxonomies(array('public' => true));
382 382
 
383 383
 	/**
384 384
 	 * Filter which taxonomies to register entities for.
@@ -387,10 +387,10 @@  discard block
 block discarded – undo
387 387
 	 *
388 388
 	 * @param string[] The taxonomy slugs.
389 389
 	 */
390
-	$taxonomies = apply_filters( 'wordpoints_register_entities_for_taxonomies', $taxonomies );
390
+	$taxonomies = apply_filters('wordpoints_register_entities_for_taxonomies', $taxonomies);
391 391
 
392
-	foreach ( $taxonomies as $slug ) {
393
-		wordpoints_register_taxonomy_entities( $slug );
392
+	foreach ($taxonomies as $slug) {
393
+		wordpoints_register_taxonomy_entities($slug);
394 394
 	}
395 395
 }
396 396
 
@@ -401,28 +401,28 @@  discard block
 block discarded – undo
401 401
  *
402 402
  * @param string $slug The slug of the post type.
403 403
  */
404
-function wordpoints_register_post_type_entities( $slug ) {
404
+function wordpoints_register_post_type_entities($slug) {
405 405
 
406 406
 	$entities = wordpoints_entities();
407 407
 	$children = $entities->children;
408 408
 
409
-	$entities->register( "post\\{$slug}", 'WordPoints_Entity_Post' );
410
-	$children->register( "post\\{$slug}", 'author', 'WordPoints_Entity_Post_Author' );
409
+	$entities->register("post\\{$slug}", 'WordPoints_Entity_Post');
410
+	$children->register("post\\{$slug}", 'author', 'WordPoints_Entity_Post_Author');
411 411
 
412
-	$supports = get_all_post_type_supports( $slug );
412
+	$supports = get_all_post_type_supports($slug);
413 413
 
414
-	if ( isset( $supports['editor'] ) ) {
415
-		$children->register( "post\\{$slug}", 'content', 'WordPoints_Entity_Post_Content' );
414
+	if (isset($supports['editor'])) {
415
+		$children->register("post\\{$slug}", 'content', 'WordPoints_Entity_Post_Content');
416 416
 	}
417 417
 
418
-	if ( isset( $supports['comments'] ) ) {
419
-		$entities->register( "comment\\{$slug}", 'WordPoints_Entity_Comment' );
420
-		$children->register( "comment\\{$slug}", "post\\{$slug}", 'WordPoints_Entity_Comment_Post' );
421
-		$children->register( "comment\\{$slug}", 'author', 'WordPoints_Entity_Comment_Author' );
418
+	if (isset($supports['comments'])) {
419
+		$entities->register("comment\\{$slug}", 'WordPoints_Entity_Comment');
420
+		$children->register("comment\\{$slug}", "post\\{$slug}", 'WordPoints_Entity_Comment_Post');
421
+		$children->register("comment\\{$slug}", 'author', 'WordPoints_Entity_Comment_Author');
422 422
 	}
423 423
 
424
-	foreach ( get_object_taxonomies( $slug ) as $taxonomy_slug ) {
425
-		$children->register( "post\\{$slug}", "terms\\{$taxonomy_slug}", 'WordPoints_Entity_Post_Terms' );
424
+	foreach (get_object_taxonomies($slug) as $taxonomy_slug) {
425
+		$children->register("post\\{$slug}", "terms\\{$taxonomy_slug}", 'WordPoints_Entity_Post_Terms');
426 426
 	}
427 427
 
428 428
 	/**
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	 *
433 433
 	 * @param string $slug The slug ("name") of the post type.
434 434
 	 */
435
-	do_action( 'wordpoints_register_post_type_entities', $slug );
435
+	do_action('wordpoints_register_post_type_entities', $slug);
436 436
 }
437 437
 
438 438
 /**
@@ -442,13 +442,13 @@  discard block
 block discarded – undo
442 442
  *
443 443
  * @param string $slug The slug of the post type.
444 444
  */
445
-function wordpoints_register_post_type_hook_events( $slug ) {
445
+function wordpoints_register_post_type_hook_events($slug) {
446 446
 
447 447
 	$event_slugs = array();
448 448
 
449 449
 	$events = wordpoints_hooks()->events;
450 450
 
451
-	if ( 'attachment' === $slug ) {
451
+	if ('attachment' === $slug) {
452 452
 
453 453
 		$event_slugs[] = 'media_upload';
454 454
 
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 			, array(
477 477
 				'actions' => array(
478 478
 					'fire'    => 'post_publish',
479
-					'reverse' => array( 'post_depublish', 'post_delete' ),
479
+					'reverse' => array('post_depublish', 'post_delete'),
480 480
 				),
481 481
 				'args'    => array(
482 482
 					"post\\{$slug}" => 'WordPoints_Hook_Arg_Dynamic',
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 		);
486 486
 	}
487 487
 
488
-	if ( post_type_supports( $slug, 'comments' ) ) {
488
+	if (post_type_supports($slug, 'comments')) {
489 489
 
490 490
 		$event_slugs[] = "comment_leave\\{$slug}";
491 491
 
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 			, 'WordPoints_Hook_Event_Comment_Leave'
495 495
 			, array(
496 496
 				'actions' => array(
497
-					'fire' => array( 'comment_approve', 'comment_new' ),
497
+					'fire' => array('comment_approve', 'comment_new'),
498 498
 					'reverse' => 'comment_deapprove',
499 499
 				),
500 500
 				'args' => array(
@@ -504,8 +504,8 @@  discard block
 block discarded – undo
504 504
 		);
505 505
 	}
506 506
 
507
-	if ( is_multisite() ) {
508
-		foreach ( $event_slugs as $event_slug ) {
507
+	if (is_multisite()) {
508
+		foreach ($event_slugs as $event_slug) {
509 509
 			$events->args->register(
510 510
 				$event_slug
511 511
 				, 'current:site'
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	 *
522 522
 	 * @param string $slug The slug ("name") of the post type.
523 523
 	 */
524
-	do_action( 'wordpoints_register_post_type_hook_events', $slug );
524
+	do_action('wordpoints_register_post_type_hook_events', $slug);
525 525
 }
526 526
 
527 527
 /**
@@ -531,13 +531,13 @@  discard block
 block discarded – undo
531 531
  *
532 532
  * @param string $slug The slug of the taxonomy.
533 533
  */
534
-function wordpoints_register_taxonomy_entities( $slug ) {
534
+function wordpoints_register_taxonomy_entities($slug) {
535 535
 
536 536
 	$entities = wordpoints_entities();
537 537
 	$children = $entities->children;
538 538
 
539
-	$entities->register( "term\\{$slug}", 'WordPoints_Entity_Term' );
540
-	$children->register( "term\\{$slug}", 'id', 'WordPoints_Entity_Term_Id' );
539
+	$entities->register("term\\{$slug}", 'WordPoints_Entity_Term');
540
+	$children->register("term\\{$slug}", 'id', 'WordPoints_Entity_Term_Id');
541 541
 
542 542
 	/**
543 543
 	 * Fired when registering the entities for a taxonomy.
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
 	 *
547 547
 	 * @param string $slug The taxonomy's slug.
548 548
 	 */
549
-	do_action( 'wordpoints_register_taxonomy_entities', $slug );
549
+	do_action('wordpoints_register_taxonomy_entities', $slug);
550 550
 }
551 551
 
552 552
 /**
@@ -558,10 +558,10 @@  discard block
 block discarded – undo
558 558
  *
559 559
  * @param WordPoints_Class_RegistryI $data_types The data types registry.
560 560
  */
561
-function wordpoints_data_types_init( $data_types ) {
561
+function wordpoints_data_types_init($data_types) {
562 562
 
563
-	$data_types->register( 'integer', 'WordPoints_Data_Type_Integer' );
564
-	$data_types->register( 'text', 'WordPoints_Data_Type_Text' );
563
+	$data_types->register('integer', 'WordPoints_Data_Type_Integer');
564
+	$data_types->register('text', 'WordPoints_Data_Type_Text');
565 565
 }
566 566
 
567 567
 /**
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
  *
577 577
  * @return bool Whether the user can view the points log.
578 578
  */
579
-function wordpoints_hooks_user_can_view_points_log( $can_view, $log ) {
579
+function wordpoints_hooks_user_can_view_points_log($can_view, $log) {
580 580
 
581
-	if ( ! $can_view ) {
581
+	if ( ! $can_view) {
582 582
 		return $can_view;
583 583
 	}
584 584
 
@@ -587,11 +587,11 @@  discard block
 block discarded – undo
587 587
 	$event_slug = $log->log_type;
588 588
 
589 589
 	/** @var WordPoints_Hook_Arg $arg */
590
-	foreach ( wordpoints_hooks()->events->args->get_children( $event_slug ) as $slug => $arg ) {
590
+	foreach (wordpoints_hooks()->events->args->get_children($event_slug) as $slug => $arg) {
591 591
 
592
-		$value = wordpoints_get_points_log_meta( $log->id, $slug, true );
592
+		$value = wordpoints_get_points_log_meta($log->id, $slug, true);
593 593
 
594
-		if ( ! $value ) {
594
+		if ( ! $value) {
595 595
 			continue;
596 596
 		}
597 597
 
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 			, $value
602 602
 		);
603 603
 
604
-		if ( ! $can_view ) {
604
+		if ( ! $can_view) {
605 605
 			break;
606 606
 		}
607 607
 	}
@@ -620,20 +620,20 @@  discard block
 block discarded – undo
620 620
  *
621 621
  * @return bool Whether the user can view this entity.
622 622
  */
623
-function wordpoints_entity_user_can_view( $user_id, $entity_slug, $entity_id ) {
623
+function wordpoints_entity_user_can_view($user_id, $entity_slug, $entity_id) {
624 624
 
625
-	$entity = wordpoints_entities()->get( $entity_slug );
625
+	$entity = wordpoints_entities()->get($entity_slug);
626 626
 
627 627
 	// If this entity type is not found, we have no way of determining whether it is
628 628
 	// safe for the user to view it.
629
-	if ( ! ( $entity instanceof WordPoints_Entity ) ) {
629
+	if ( ! ($entity instanceof WordPoints_Entity)) {
630 630
 		return false;
631 631
 	}
632 632
 
633 633
 	$can_view = true;
634 634
 
635
-	if ( $entity instanceof WordPoints_Entity_Restricted_VisibilityI ) {
636
-		$can_view = $entity->user_can_view( $user_id, $entity_id );
635
+	if ($entity instanceof WordPoints_Entity_Restricted_VisibilityI) {
636
+		$can_view = $entity->user_can_view($user_id, $entity_id);
637 637
 	}
638 638
 
639 639
 	/**
@@ -664,8 +664,8 @@  discard block
 block discarded – undo
664 664
  */
665 665
 function wordpoints_apps() {
666 666
 
667
-	if ( ! isset( WordPoints_App::$main ) ) {
668
-		WordPoints_App::$main = new WordPoints_App( 'apps' );
667
+	if ( ! isset(WordPoints_App::$main)) {
668
+		WordPoints_App::$main = new WordPoints_App('apps');
669 669
 	}
670 670
 
671 671
 	return WordPoints_App::$main;
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
  */
681 681
 function wordpoints_hooks() {
682 682
 
683
-	if ( ! isset( WordPoints_App::$main ) ) {
683
+	if ( ! isset(WordPoints_App::$main)) {
684 684
 		wordpoints_apps();
685 685
 	}
686 686
 
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
  */
697 697
 function wordpoints_entities() {
698 698
 
699
-	if ( ! isset( WordPoints_App::$main ) ) {
699
+	if ( ! isset(WordPoints_App::$main)) {
700 700
 		wordpoints_apps();
701 701
 	}
702 702
 
@@ -712,13 +712,13 @@  discard block
 block discarded – undo
712 712
  *
713 713
  * @param WordPoints_App $app The main apps app.
714 714
  */
715
-function wordpoints_apps_init( $app ) {
715
+function wordpoints_apps_init($app) {
716 716
 
717 717
 	$apps = $app->sub_apps;
718 718
 
719
-	$apps->register( 'hooks', 'WordPoints_Hooks' );
720
-	$apps->register( 'entities', 'WordPoints_App_Registry' );
721
-	$apps->register( 'data_types', 'WordPoints_Class_Registry' );
719
+	$apps->register('hooks', 'WordPoints_Hooks');
720
+	$apps->register('entities', 'WordPoints_App_Registry');
721
+	$apps->register('data_types', 'WordPoints_Class_Registry');
722 722
 }
723 723
 
724 724
 /**
@@ -731,19 +731,19 @@  discard block
 block discarded – undo
731 731
  *
732 732
  * @return object|false The constructed object, or false if to many args were passed.
733 733
  */
734
-function wordpoints_construct_class_with_args( $class_name, array $args ) {
734
+function wordpoints_construct_class_with_args($class_name, array $args) {
735 735
 
736
-	switch ( count( $args ) ) {
736
+	switch (count($args)) {
737 737
 		case 0:
738 738
 			return new $class_name();
739 739
 		case 1:
740
-			return new $class_name( $args[0] );
740
+			return new $class_name($args[0]);
741 741
 		case 2:
742
-			return new $class_name( $args[0], $args[1] );
742
+			return new $class_name($args[0], $args[1]);
743 743
 		case 3:
744
-			return new $class_name( $args[0], $args[1], $args[2] );
744
+			return new $class_name($args[0], $args[1], $args[2]);
745 745
 		case 4:
746
-			return new $class_name( $args[0], $args[1], $args[2], $args[3] );
746
+			return new $class_name($args[0], $args[1], $args[2], $args[3]);
747 747
 		default:
748 748
 			return false;
749 749
 	}
@@ -765,13 +765,13 @@  discard block
 block discarded – undo
765 765
  * @return array The slug parsed into the 'generic' and 'dynamic' portions. If the
766 766
  *               slug is not dynamic, the value of each of those keys will be false.
767 767
  */
768
-function wordpoints_parse_dynamic_slug( $slug ) {
768
+function wordpoints_parse_dynamic_slug($slug) {
769 769
 
770
-	$parsed = array( 'dynamic' => false, 'generic' => false );
770
+	$parsed = array('dynamic' => false, 'generic' => false);
771 771
 
772
-	$parts = explode( '\\', $slug, 2 );
772
+	$parts = explode('\\', $slug, 2);
773 773
 
774
-	if ( isset( $parts[1] ) ) {
774
+	if (isset($parts[1])) {
775 775
 		$parsed['dynamic'] = $parts[1];
776 776
 		$parsed['generic'] = $parts[0];
777 777
 	}
@@ -810,28 +810,28 @@  discard block
 block discarded – undo
810 810
  *                     contexts, indexed by context slug, or false if any of the
811 811
  *                     contexts isn't current.
812 812
  */
813
-function wordpoints_entities_get_current_context_id( $slug ) {
813
+function wordpoints_entities_get_current_context_id($slug) {
814 814
 
815 815
 	$current_context = array();
816 816
 
817 817
 	/** @var WordPoints_Class_Registry $contexts */
818 818
 	$contexts = wordpoints_entities()->contexts;
819 819
 
820
-	while ( $slug ) {
820
+	while ($slug) {
821 821
 
822
-		$context = $contexts->get( $slug );
822
+		$context = $contexts->get($slug);
823 823
 
824
-		if ( ! $context instanceof WordPoints_Entity_Context ) {
824
+		if ( ! $context instanceof WordPoints_Entity_Context) {
825 825
 			return false;
826 826
 		}
827 827
 
828 828
 		$id = $context->get_current_id();
829 829
 
830
-		if ( false === $id ) {
830
+		if (false === $id) {
831 831
 			return false;
832 832
 		}
833 833
 
834
-		$current_context[ $slug ] = $id;
834
+		$current_context[$slug] = $id;
835 835
 
836 836
 		$slug = $context->get_parent_slug();
837 837
 	}
@@ -852,22 +852,22 @@  discard block
 block discarded – undo
852 852
  */
853 853
 function wordpoints_is_network_context() {
854 854
 
855
-	if ( ! is_multisite() ) {
855
+	if ( ! is_multisite()) {
856 856
 		return false;
857 857
 	}
858 858
 
859
-	if ( is_network_admin() ) {
859
+	if (is_network_admin()) {
860 860
 		return true;
861 861
 	}
862 862
 
863 863
 	// See https://core.trac.wordpress.org/ticket/22589
864 864
 	if (
865
-		defined( 'DOING_AJAX' )
865
+		defined('DOING_AJAX')
866 866
 		&& DOING_AJAX
867
-		&& isset( $_SERVER['HTTP_REFERER'] )
867
+		&& isset($_SERVER['HTTP_REFERER'])
868 868
 		&& preg_match(
869
-			'#^' . preg_quote( network_admin_url(), '#' ) . '#i'
870
-			, esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) )
869
+			'#^'.preg_quote(network_admin_url(), '#').'#i'
870
+			, esc_url_raw(wp_unslash($_SERVER['HTTP_REFERER']))
871 871
 		)
872 872
 	) {
873 873
 		return true;
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
 	 *
881 881
 	 * @param bool $in_network_context Whether we are in network context.
882 882
 	 */
883
-	return apply_filters( 'wordpoints_is_network_context', false );
883
+	return apply_filters('wordpoints_is_network_context', false);
884 884
 }
885 885
 
886 886
 /**
@@ -894,21 +894,21 @@  discard block
 block discarded – undo
894 894
  *
895 895
  * @return string The primary arg's GUID, JSON encoded.
896 896
  */
897
-function wordpoints_hooks_get_event_primary_arg_guid_json( WordPoints_Hook_Event_Args $event_args ) {
897
+function wordpoints_hooks_get_event_primary_arg_guid_json(WordPoints_Hook_Event_Args $event_args) {
898 898
 
899 899
 	$entity = $event_args->get_primary_arg();
900 900
 
901
-	if ( ! $entity ) {
901
+	if ( ! $entity) {
902 902
 		return '';
903 903
 	}
904 904
 
905 905
 	$the_guid = $entity->get_the_guid();
906 906
 
907
-	if ( ! $the_guid ) {
907
+	if ( ! $the_guid) {
908 908
 		return '';
909 909
 	}
910 910
 
911
-	return wp_json_encode( $the_guid );
911
+	return wp_json_encode($the_guid);
912 912
 }
913 913
 
914 914
 /**
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
  */
922 922
 function wordpoints_hooks_api_add_global_cache_groups() {
923 923
 
924
-	if ( function_exists( 'wp_cache_add_global_groups' ) ) {
924
+	if (function_exists('wp_cache_add_global_groups')) {
925 925
 
926 926
 		wp_cache_add_global_groups(
927 927
 			array(
@@ -947,8 +947,8 @@  discard block
 block discarded – undo
947 947
  * @return string The escaped identifier. Already quoted, do not place within
948 948
  *                backticks.
949 949
  */
950
-function wordpoints_escape_mysql_identifier( $identifier ) {
951
-	return '`' . str_replace( '`', '``', $identifier ) . '`';
950
+function wordpoints_escape_mysql_identifier($identifier) {
951
+	return '`'.str_replace('`', '``', $identifier).'`';
952 952
 }
953 953
 
954 954
 // EOF
Please login to merge, or discard this patch.
src/includes/classes/hook/extension/blocker.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@
 block discarded – undo
24 24
 	/**
25 25
 	 * @since 1.0.0
26 26
 	 */
27
-	public function validate_action_type_settings( $settings ) {
27
+	public function validate_action_type_settings($settings) {
28 28
 		return (bool) $settings;
29 29
 	}
30 30
 
31 31
 	/**
32 32
 	 * @since 1.0.0
33 33
 	 */
34
-	public function should_hit( WordPoints_Hook_Fire $fire ) {
35
-		return ! $this->get_settings_from_fire( $fire );
34
+	public function should_hit(WordPoints_Hook_Fire $fire) {
35
+		return ! $this->get_settings_from_fire($fire);
36 36
 	}
37 37
 }
38 38
 
Please login to merge, or discard this patch.
src/includes/classes/hook/extension/periods.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -25,11 +25,11 @@  discard block
 block discarded – undo
25 25
 	public function get_ui_script_data() {
26 26
 
27 27
 		$periods = array(
28
-			MINUTE_IN_SECONDS   => __( 'Minute', 'wordpoints' ),
29
-			HOUR_IN_SECONDS     => __( 'Hour',   'wordpoints' ),
30
-			DAY_IN_SECONDS      => __( 'Day',    'wordpoints' ),
31
-			WEEK_IN_SECONDS     => __( 'Week',   'wordpoints' ),
32
-			30 * DAY_IN_SECONDS => __( 'Month',  'wordpoints' ),
28
+			MINUTE_IN_SECONDS   => __('Minute', 'wordpoints'),
29
+			HOUR_IN_SECONDS     => __('Hour', 'wordpoints'),
30
+			DAY_IN_SECONDS      => __('Day', 'wordpoints'),
31
+			WEEK_IN_SECONDS     => __('Week', 'wordpoints'),
32
+			30 * DAY_IN_SECONDS => __('Month', 'wordpoints'),
33 33
 		);
34 34
 
35 35
 		/**
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 		 *
40 40
 		 * @param string[] $periods The period titles, indexed by length in seconds.
41 41
 		 */
42
-		$periods = apply_filters( 'wordpoints_hooks_ui_data_periods', $periods );
42
+		$periods = apply_filters('wordpoints_hooks_ui_data_periods', $periods);
43 43
 
44 44
 		return array(
45 45
 			'periods' => $periods,
46 46
 			'l10n' => array(
47
-				'label' => __( 'Trigger reaction no more than once per:', 'wordpoints' ),
47
+				'label' => __('Trigger reaction no more than once per:', 'wordpoints'),
48 48
 			),
49 49
 		);
50 50
 	}
@@ -58,25 +58,25 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @return array The validated periods.
60 60
 	 */
61
-	protected function validate_action_type_settings( $periods ) {
61
+	protected function validate_action_type_settings($periods) {
62 62
 
63
-		if ( ! is_array( $periods ) ) {
63
+		if ( ! is_array($periods)) {
64 64
 
65 65
 			$this->validator->add_error(
66
-				__( 'Periods do not match expected format.', 'wordpoints' )
66
+				__('Periods do not match expected format.', 'wordpoints')
67 67
 			);
68 68
 
69 69
 			return array();
70 70
 		}
71 71
 
72
-		foreach ( $periods as $index => $period ) {
72
+		foreach ($periods as $index => $period) {
73 73
 
74
-			$this->validator->push_field( $index );
74
+			$this->validator->push_field($index);
75 75
 
76
-			$period = $this->validate_period( $period );
76
+			$period = $this->validate_period($period);
77 77
 
78
-			if ( $period ) {
79
-				$periods[ $index ] = $period;
78
+			if ($period) {
79
+				$periods[$index] = $period;
80 80
 			}
81 81
 
82 82
 			$this->validator->pop_field();
@@ -94,30 +94,30 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @return array|false The validated period, or false if invalid.
96 96
 	 */
97
-	protected function validate_period( $period ) {
97
+	protected function validate_period($period) {
98 98
 
99
-		if ( ! is_array( $period ) ) {
99
+		if ( ! is_array($period)) {
100 100
 			$this->validator->add_error(
101
-				__( 'Period does not match expected format.', 'wordpoints' )
101
+				__('Period does not match expected format.', 'wordpoints')
102 102
 			);
103 103
 
104 104
 			return false;
105 105
 		}
106 106
 
107
-		if ( isset( $period['args'] ) ) {
108
-			$this->validate_period_args( $period['args'] );
107
+		if (isset($period['args'])) {
108
+			$this->validate_period_args($period['args']);
109 109
 		}
110 110
 
111
-		if ( ! isset( $period['length'] ) ) {
111
+		if ( ! isset($period['length'])) {
112 112
 
113 113
 			$this->validator->add_error(
114
-				__( 'Period length setting is missing.', 'wordpoints' )
114
+				__('Period length setting is missing.', 'wordpoints')
115 115
 			);
116 116
 
117
-		} elseif ( false === wordpoints_posint( $period['length'] ) ) {
117
+		} elseif (false === wordpoints_posint($period['length'])) {
118 118
 
119 119
 			$this->validator->add_error(
120
-				__( 'Period length must be a positive integer.', 'wordpoints' )
120
+				__('Period length must be a positive integer.', 'wordpoints')
121 121
 				, 'length'
122 122
 			);
123 123
 
@@ -134,34 +134,34 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @param mixed $args The args the period is related to.
136 136
 	 */
137
-	protected function validate_period_args( $args ) {
137
+	protected function validate_period_args($args) {
138 138
 
139
-		if ( ! is_array( $args ) ) {
139
+		if ( ! is_array($args)) {
140 140
 
141 141
 			$this->validator->add_error(
142
-				__( 'Period does not match expected format.', 'wordpoints' )
142
+				__('Period does not match expected format.', 'wordpoints')
143 143
 				, 'args'
144 144
 			);
145 145
 
146 146
 			return;
147 147
 		}
148 148
 
149
-		$this->validator->push_field( 'args' );
149
+		$this->validator->push_field('args');
150 150
 
151
-		foreach ( $args as $index => $hierarchy ) {
151
+		foreach ($args as $index => $hierarchy) {
152 152
 
153
-			$this->validator->push_field( $index );
153
+			$this->validator->push_field($index);
154 154
 
155
-			if ( ! is_array( $hierarchy ) ) {
155
+			if ( ! is_array($hierarchy)) {
156 156
 
157 157
 				$this->validator->add_error(
158
-					__( 'Period does not match expected format.', 'wordpoints' )
158
+					__('Period does not match expected format.', 'wordpoints')
159 159
 				);
160 160
 
161
-			} elseif ( ! $this->event_args->get_from_hierarchy( $hierarchy ) ) {
161
+			} elseif ( ! $this->event_args->get_from_hierarchy($hierarchy)) {
162 162
 
163 163
 				$this->validator->add_error(
164
-					__( 'Invalid period.', 'wordpoints' ) // TODO better error message
164
+					__('Invalid period.', 'wordpoints') // TODO better error message
165 165
 				);
166 166
 			}
167 167
 
@@ -174,18 +174,18 @@  discard block
 block discarded – undo
174 174
 	/**
175 175
 	 * @since 1.0.0
176 176
 	 */
177
-	public function should_hit( WordPoints_Hook_Fire $fire ) {
177
+	public function should_hit(WordPoints_Hook_Fire $fire) {
178 178
 
179
-		$periods = $this->get_settings_from_fire( $fire );
179
+		$periods = $this->get_settings_from_fire($fire);
180 180
 
181
-		if ( empty( $periods ) ) {
181
+		if (empty($periods)) {
182 182
 			return true;
183 183
 		}
184 184
 
185 185
 		$this->event_args = $fire->event_args;
186 186
 
187
-		foreach ( $periods as $period ) {
188
-			if ( ! $this->has_period_ended( $period, $fire->reaction ) ) {
187
+		foreach ($periods as $period) {
188
+			if ( ! $this->has_period_ended($period, $fire->reaction)) {
189 189
 				return false;
190 190
 			}
191 191
 		}
@@ -209,24 +209,24 @@  discard block
 block discarded – undo
209 209
 	) {
210 210
 
211 211
 		$period = $this->get_period_by_reaction(
212
-			$this->get_period_signature( $settings, $reaction )
212
+			$this->get_period_signature($settings, $reaction)
213 213
 			, $reaction
214 214
 		);
215 215
 
216 216
 		// If the period isn't found, we know that we can still fire.
217
-		if ( ! $period ) {
217
+		if ( ! $period) {
218 218
 			return true;
219 219
 		}
220 220
 
221
-		$now = current_time( 'timestamp' );
222
-		$hit_time = strtotime( $period->date, $now );
221
+		$now = current_time('timestamp');
222
+		$hit_time = strtotime($period->date, $now);
223 223
 
224
-		if ( ! empty( $settings['relative'] ) ) {
225
-			return ( $hit_time < $now - $settings['length'] );
224
+		if ( ! empty($settings['relative'])) {
225
+			return ($hit_time < $now - $settings['length']);
226 226
 		} else {
227 227
 			return (
228
-				(int) ( $hit_time / $settings['length'] )
229
-				< (int) ( $now / $settings['length'] )
228
+				(int) ($hit_time / $settings['length'])
229
+				< (int) ($now / $settings['length'])
230 230
 			);
231 231
 		}
232 232
 	}
@@ -240,24 +240,24 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @return array The arg values.
242 242
 	 */
243
-	protected function get_arg_values( array $period_args ) {
243
+	protected function get_arg_values(array $period_args) {
244 244
 
245 245
 		$values = array();
246 246
 
247
-		foreach ( $period_args as $arg_hierarchy ) {
247
+		foreach ($period_args as $arg_hierarchy) {
248 248
 
249 249
 			$arg = $this->event_args->get_from_hierarchy(
250 250
 				$arg_hierarchy
251 251
 			);
252 252
 
253
-			if ( ! $arg instanceof WordPoints_EntityishI ) {
253
+			if ( ! $arg instanceof WordPoints_EntityishI) {
254 254
 				continue;
255 255
 			}
256 256
 
257
-			$values[ implode( '.', $arg_hierarchy ) ] = $arg->get_the_value();
257
+			$values[implode('.', $arg_hierarchy)] = $arg->get_the_value();
258 258
 		}
259 259
 
260
-		ksort( $values );
260
+		ksort($values);
261 261
 
262 262
 		return $values;
263 263
 	}
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
 	 *
272 272
 	 * @return object|false The period data, or false if not found.
273 273
 	 */
274
-	protected function get_period( $period_id ) {
274
+	protected function get_period($period_id) {
275 275
 
276
-		$period = wp_cache_get( $period_id, 'wordpoints_hook_periods' );
276
+		$period = wp_cache_get($period_id, 'wordpoints_hook_periods');
277 277
 
278
-		if ( ! $period ) {
278
+		if ( ! $period) {
279 279
 
280 280
 			global $wpdb;
281 281
 
@@ -292,11 +292,11 @@  discard block
 block discarded – undo
292 292
 				)
293 293
 			);
294 294
 
295
-			if ( ! $period ) {
295
+			if ( ! $period) {
296 296
 				return false;
297 297
 			}
298 298
 
299
-			wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' );
299
+			wp_cache_set($period->id, $period, 'wordpoints_hook_periods');
300 300
 		}
301 301
 
302 302
 		return $period;
@@ -320,14 +320,14 @@  discard block
 block discarded – undo
320 320
 
321 321
 		$reaction_guid = $reaction->get_guid();
322 322
 
323
-		$cache_key = wp_json_encode( $reaction_guid ) . "-{$signature}";
323
+		$cache_key = wp_json_encode($reaction_guid)."-{$signature}";
324 324
 
325 325
 		// Before we run the query, we try to lookup the ID in the cache.
326
-		$period_id = wp_cache_get( $cache_key, 'wordpoints_hook_period_ids_by_reaction' );
326
+		$period_id = wp_cache_get($cache_key, 'wordpoints_hook_period_ids_by_reaction');
327 327
 
328 328
 		// If we found it, we can retrieve the period by ID instead.
329
-		if ( $period_id ) {
330
-			return $this->get_period( $period_id );
329
+		if ($period_id) {
330
+			return $this->get_period($period_id);
331 331
 		}
332 332
 
333 333
 		global $wpdb;
@@ -351,17 +351,17 @@  discard block
 block discarded – undo
351 351
 				, $signature
352 352
 				, $reaction_guid['reactor']
353 353
 				, $reaction_guid['store']
354
-				, wp_json_encode( $reaction_guid['context_id'] )
354
+				, wp_json_encode($reaction_guid['context_id'])
355 355
 				, $reaction_guid['id']
356 356
 			)
357 357
 		);
358 358
 
359
-		if ( ! $period ) {
359
+		if ( ! $period) {
360 360
 			return false;
361 361
 		}
362 362
 
363
-		wp_cache_set( $cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction' );
364
-		wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' );
363
+		wp_cache_set($cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction');
364
+		wp_cache_set($period->id, $period, 'wordpoints_hook_periods');
365 365
 
366 366
 		return $period;
367 367
 	}
@@ -369,20 +369,20 @@  discard block
 block discarded – undo
369 369
 	/**
370 370
 	 * @since 1.0.0
371 371
 	 */
372
-	public function after_hit( WordPoints_Hook_Fire $fire ) {
372
+	public function after_hit(WordPoints_Hook_Fire $fire) {
373 373
 
374
-		$periods = $this->get_settings_from_fire( $fire );
374
+		$periods = $this->get_settings_from_fire($fire);
375 375
 
376
-		if ( empty( $periods ) ) {
376
+		if (empty($periods)) {
377 377
 			return;
378 378
 		}
379 379
 
380 380
 		$this->event_args = $fire->event_args;
381 381
 
382
-		foreach ( $periods as $settings ) {
382
+		foreach ($periods as $settings) {
383 383
 
384 384
 			$this->add_period(
385
-				$this->get_period_signature( $settings, $fire->reaction )
385
+				$this->get_period_signature($settings, $fire->reaction)
386 386
 				, $fire
387 387
 			);
388 388
 		}
@@ -407,14 +407,14 @@  discard block
 block discarded – undo
407 407
 		WordPoints_Hook_ReactionI $reaction
408 408
 	) {
409 409
 
410
-		if ( isset( $settings['args'] ) ) {
410
+		if (isset($settings['args'])) {
411 411
 			$period_args = $settings['args'];
412 412
 		} else {
413
-			$period_args = array( $reaction->get_meta( 'target' ) );
413
+			$period_args = array($reaction->get_meta('target'));
414 414
 		}
415 415
 
416 416
 		return wordpoints_hash(
417
-			wp_json_encode( $this->get_arg_values( $period_args ) )
417
+			wp_json_encode($this->get_arg_values($period_args))
418 418
 		);
419 419
 	}
420 420
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 	 *
429 429
 	 * @return false|object The period data, or false if not found.
430 430
 	 */
431
-	protected function add_period( $signature, WordPoints_Hook_Fire $fire ) {
431
+	protected function add_period($signature, WordPoints_Hook_Fire $fire) {
432 432
 
433 433
 		global $wpdb;
434 434
 
@@ -438,17 +438,17 @@  discard block
 block discarded – undo
438 438
 				'hit_id' => $fire->hit_id,
439 439
 				'signature' => $signature,
440 440
 			)
441
-			, array( '%d', '%s' )
441
+			, array('%d', '%s')
442 442
 		);
443 443
 
444
-		if ( ! $inserted ) {
444
+		if ( ! $inserted) {
445 445
 			return false;
446 446
 		}
447 447
 
448 448
 		$period_id = $wpdb->insert_id;
449 449
 
450 450
 		wp_cache_set(
451
-			wp_json_encode( $fire->reaction->get_guid() ) . "-{$signature}"
451
+			wp_json_encode($fire->reaction->get_guid())."-{$signature}"
452 452
 			, $period_id
453 453
 			, 'wordpoints_hook_period_ids_by_reaction'
454 454
 		);
Please login to merge, or discard this patch.
src/includes/classes/hook/extension/conditions.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
 
43 43
 		$conditions_data = array();
44 44
 
45
-		foreach ( $this->conditions->get_all() as $data_type => $conditions ) {
46
-			foreach ( $conditions as $slug => $condition ) {
45
+		foreach ($this->conditions->get_all() as $data_type => $conditions) {
46
+			foreach ($conditions as $slug => $condition) {
47 47
 
48
-				if ( ! ( $condition instanceof WordPoints_Hook_Condition ) ) {
48
+				if ( ! ($condition instanceof WordPoints_Hook_Condition)) {
49 49
 					continue;
50 50
 				}
51 51
 
52
-				$conditions_data[ $data_type ][ $slug ] = array(
52
+				$conditions_data[$data_type][$slug] = array(
53 53
 					'slug'      => $slug,
54 54
 					'data_type' => $data_type,
55 55
 					'title'     => $condition->get_title(),
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 			}
59 59
 		}
60 60
 
61
-		return array( 'conditions' => $conditions_data );
61
+		return array('conditions' => $conditions_data);
62 62
 	}
63 63
 
64 64
 	/**
65 65
 	 * @since 1.0.0
66 66
 	 */
67
-	protected function validate_action_type_settings( $settings ) {
68
-		return $this->validate_conditions( $settings );
67
+	protected function validate_action_type_settings($settings) {
68
+		return $this->validate_conditions($settings);
69 69
 	}
70 70
 
71 71
 	/**
@@ -78,36 +78,36 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @return array The validated settings.
80 80
 	 */
81
-	public function validate_conditions( $conditions, WordPoints_Hook_Event_Args $event_args = null ) {
81
+	public function validate_conditions($conditions, WordPoints_Hook_Event_Args $event_args = null) {
82 82
 
83
-		if ( $event_args ) {
83
+		if ($event_args) {
84 84
 			$this->event_args = $event_args;
85 85
 			$this->validator = $event_args->get_validator();
86 86
 		}
87 87
 
88
-		if ( ! is_array( $conditions ) ) {
88
+		if ( ! is_array($conditions)) {
89 89
 
90 90
 			$this->validator->add_error(
91
-				__( 'Conditions do not match expected format.', 'wordpoints' )
91
+				__('Conditions do not match expected format.', 'wordpoints')
92 92
 			);
93 93
 
94 94
 			return array();
95 95
 		}
96 96
 
97
-		foreach ( $conditions as $arg_slug => $sub_args ) {
97
+		foreach ($conditions as $arg_slug => $sub_args) {
98 98
 
99
-			if ( '_conditions' === $arg_slug ) {
99
+			if ('_conditions' === $arg_slug) {
100 100
 
101
-				$this->validator->push_field( $arg_slug );
101
+				$this->validator->push_field($arg_slug);
102 102
 
103
-				foreach ( $sub_args as $index => $settings ) {
103
+				foreach ($sub_args as $index => $settings) {
104 104
 
105
-					$this->validator->push_field( $index );
105
+					$this->validator->push_field($index);
106 106
 
107
-					$condition = $this->validate_condition( $settings );
107
+					$condition = $this->validate_condition($settings);
108 108
 
109
-					if ( $condition ) {
110
-						$sub_args[ $index ] = $condition;
109
+					if ($condition) {
110
+						$sub_args[$index] = $condition;
111 111
 					}
112 112
 
113 113
 					$this->validator->pop_field();
@@ -117,18 +117,18 @@  discard block
 block discarded – undo
117 117
 
118 118
 			} else {
119 119
 
120
-				if ( ! $this->event_args->descend( $arg_slug ) ) {
120
+				if ( ! $this->event_args->descend($arg_slug)) {
121 121
 					continue;
122 122
 				}
123 123
 
124
-				$sub_args = $this->validate_action_type_settings( $sub_args );
124
+				$sub_args = $this->validate_action_type_settings($sub_args);
125 125
 
126
-				$conditions[ $arg_slug ] = $sub_args;
126
+				$conditions[$arg_slug] = $sub_args;
127 127
 
128 128
 				$this->event_args->ascend();
129 129
 			}
130 130
 
131
-			$conditions[ $arg_slug ] = $sub_args;
131
+			$conditions[$arg_slug] = $sub_args;
132 132
 		}
133 133
 
134 134
 		return $conditions;
@@ -144,32 +144,32 @@  discard block
 block discarded – undo
144 144
 	 * @return array|false The validated conditions settings, or false if unable to
145 145
 	 *                     validate.
146 146
 	 */
147
-	protected function validate_condition( $settings ) {
147
+	protected function validate_condition($settings) {
148 148
 
149
-		if ( ! isset( $settings['type'] ) ) {
150
-			$this->validator->add_error( __( 'Condition type is missing.', 'wordpoints' ) );
149
+		if ( ! isset($settings['type'])) {
150
+			$this->validator->add_error(__('Condition type is missing.', 'wordpoints'));
151 151
 			return false;
152 152
 		}
153 153
 
154 154
 		$arg = $this->event_args->get_current();
155 155
 
156
-		$data_type = $this->get_data_type( $arg );
156
+		$data_type = $this->get_data_type($arg);
157 157
 
158
-		if ( ! $data_type ) {
158
+		if ( ! $data_type) {
159 159
 			$this->validator->add_error(
160
-				__( 'This type of condition does not work for the selected attribute.', 'wordpoints' )
160
+				__('This type of condition does not work for the selected attribute.', 'wordpoints')
161 161
 			);
162 162
 
163 163
 			return false;
164 164
 		}
165 165
 
166
-		$condition = wordpoints_hooks()->conditions->get( $data_type, $settings['type'] );
166
+		$condition = wordpoints_hooks()->conditions->get($data_type, $settings['type']);
167 167
 
168
-		if ( ! $condition ) {
168
+		if ( ! $condition) {
169 169
 
170 170
 			$this->validator->add_error(
171 171
 				sprintf(
172
-					__( 'Unknown condition type &#8220;%s&#8221;.', 'wordpoints' )
172
+					__('Unknown condition type &#8220;%s&#8221;.', 'wordpoints')
173 173
 					, $settings['type']
174 174
 				)
175 175
 				, 'type'
@@ -178,17 +178,17 @@  discard block
 block discarded – undo
178 178
 			return false;
179 179
 		}
180 180
 
181
-		if ( ! isset( $settings['settings'] ) ) {
182
-			$this->validator->add_error( __( 'Condition settings are missing.', 'wordpoints' ) );
181
+		if ( ! isset($settings['settings'])) {
182
+			$this->validator->add_error(__('Condition settings are missing.', 'wordpoints'));
183 183
 			return false;
184 184
 		}
185 185
 
186
-		$this->validator->push_field( 'settings' );
186
+		$this->validator->push_field('settings');
187 187
 
188 188
 		// The condition may call this object's validate_settings() method to
189 189
 		// validate some sub-conditions. When that happens, these properties will be
190 190
 		// reset, so we need to back up their values and then restore them below.
191
-		$backup = array( $this->validator, $this->event_args );
191
+		$backup = array($this->validator, $this->event_args);
192 192
 
193 193
 		$settings['settings'] = $condition->validate_settings(
194 194
 			$arg
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 			, $this->validator
197 197
 		);
198 198
 
199
-		list( $this->validator, $this->event_args ) = $backup;
199
+		list($this->validator, $this->event_args) = $backup;
200 200
 
201 201
 		$this->validator->pop_field();
202 202
 
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
 	/**
207 207
 	 * @since 1.0.0
208 208
 	 */
209
-	public function should_hit( WordPoints_Hook_Fire $fire ) {
209
+	public function should_hit(WordPoints_Hook_Fire $fire) {
210 210
 
211
-		$conditions = $this->get_settings_from_fire( $fire );
211
+		$conditions = $this->get_settings_from_fire($fire);
212 212
 
213
-		if ( $conditions && ! $this->conditions_are_met( $conditions, $fire->event_args ) ) {
213
+		if ($conditions && ! $this->conditions_are_met($conditions, $fire->event_args)) {
214 214
 			return false;
215 215
 		}
216 216
 
@@ -232,35 +232,35 @@  discard block
 block discarded – undo
232 232
 		WordPoints_Hook_Event_Args $event_args
233 233
 	) {
234 234
 
235
-		foreach ( $conditions as $arg_slug => $sub_args ) {
235
+		foreach ($conditions as $arg_slug => $sub_args) {
236 236
 
237
-			$event_args->descend( $arg_slug );
237
+			$event_args->descend($arg_slug);
238 238
 
239
-			if ( isset( $sub_args['_conditions'] ) ) {
239
+			if (isset($sub_args['_conditions'])) {
240 240
 
241
-				foreach ( $sub_args['_conditions'] as $settings ) {
241
+				foreach ($sub_args['_conditions'] as $settings) {
242 242
 
243 243
 					$condition = $this->conditions->get(
244
-						$this->get_data_type( $event_args->get_current() )
244
+						$this->get_data_type($event_args->get_current())
245 245
 						, $settings['type']
246 246
 					);
247 247
 
248
-					$is_met = $condition->is_met( $settings['settings'], $event_args );
248
+					$is_met = $condition->is_met($settings['settings'], $event_args);
249 249
 
250
-					if ( ! $is_met ) {
250
+					if ( ! $is_met) {
251 251
 						$event_args->ascend();
252 252
 						return false;
253 253
 					}
254 254
 				}
255 255
 
256
-				unset( $sub_args['_conditions'] );
256
+				unset($sub_args['_conditions']);
257 257
 			}
258 258
 
259
-			$are_met = $this->conditions_are_met( $sub_args, $event_args );
259
+			$are_met = $this->conditions_are_met($sub_args, $event_args);
260 260
 
261 261
 			$event_args->ascend();
262 262
 
263
-			if ( ! $are_met ) {
263
+			if ( ! $are_met) {
264 264
 				return false;
265 265
 			}
266 266
 		}
@@ -277,13 +277,13 @@  discard block
 block discarded – undo
277 277
 	 *
278 278
 	 * @return string|false The data type, or false.
279 279
 	 */
280
-	protected function get_data_type( $arg ) {
280
+	protected function get_data_type($arg) {
281 281
 
282
-		if ( $arg instanceof WordPoints_Entity_Attr ) {
282
+		if ($arg instanceof WordPoints_Entity_Attr) {
283 283
 			$data_type = $arg->get_data_type();
284
-		} elseif ( $arg instanceof WordPoints_Entity_Array ) {
284
+		} elseif ($arg instanceof WordPoints_Entity_Array) {
285 285
 			$data_type = 'entity_array';
286
-		} elseif ( $arg instanceof WordPoints_Entity ) {
286
+		} elseif ($arg instanceof WordPoints_Entity) {
287 287
 			$data_type = 'entity';
288 288
 		} else {
289 289
 			$data_type = false;
Please login to merge, or discard this patch.
src/includes/classes/hook/condition/entity/array/contains.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 * @since 1.0.0
57 57
 	 */
58 58
 	public function get_title() {
59
-		return __( 'Contains', 'wordpoints' );
59
+		return __('Contains', 'wordpoints');
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
 		return array(
67 67
 			'min' => array(
68 68
 				'slug'    => 'min',
69
-				'label'   => __( 'Minimum number of items', 'wordpoints' ),
69
+				'label'   => __('Minimum number of items', 'wordpoints'),
70 70
 				'type'    => 'number',
71 71
 				'default' => 1,
72 72
 			),
73 73
 			'max' => array(
74 74
 				'slug'  => 'max',
75
-				'label' => __( 'Maximum number of items', 'wordpoints' ),
75
+				'label' => __('Maximum number of items', 'wordpoints'),
76 76
 				'type'  => 'number',
77 77
 			),
78 78
 		);
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 
93 93
 		$this->validate_count();
94 94
 
95
-		if ( isset( $settings['conditions'] ) ) {
96
-			$this->validate_conditions( $arg );
95
+		if (isset($settings['conditions'])) {
96
+			$this->validate_conditions($arg);
97 97
 		}
98 98
 
99 99
 		return $this->settings;
@@ -107,31 +107,31 @@  discard block
 block discarded – undo
107 107
 	protected function validate_count() {
108 108
 
109 109
 		if (
110
-			! empty( $this->settings['max'] )
111
-			&& ! wordpoints_posint( $this->settings['max'] )
110
+			! empty($this->settings['max'])
111
+			&& ! wordpoints_posint($this->settings['max'])
112 112
 		) {
113 113
 			$this->validator->add_error(
114
-				__( 'The maximum must be a positive integer.', 'wordpoints' )
114
+				__('The maximum must be a positive integer.', 'wordpoints')
115 115
 				, 'max'
116 116
 			);
117 117
 		}
118 118
 
119
-		if ( ! empty( $this->settings['min'] ) ) {
119
+		if ( ! empty($this->settings['min'])) {
120 120
 
121
-			if ( ! wordpoints_posint( $this->settings['min'] ) ) {
121
+			if ( ! wordpoints_posint($this->settings['min'])) {
122 122
 
123 123
 				$this->validator->add_error(
124
-					__( 'The minimum must be a positive integer.', 'wordpoints' )
124
+					__('The minimum must be a positive integer.', 'wordpoints')
125 125
 					, 'min'
126 126
 				);
127 127
 
128 128
 			} elseif (
129
-				! empty( $this->settings['max'] )
129
+				! empty($this->settings['max'])
130 130
 				&& $this->settings['max'] < $this->settings['min']
131 131
 			) {
132 132
 
133 133
 				$this->validator->add_error(
134
-					__( 'The minimum must be less than the maximum.', 'wordpoints' )
134
+					__('The minimum must be less than the maximum.', 'wordpoints')
135 135
 					, 'min'
136 136
 				);
137 137
 			}
@@ -145,24 +145,24 @@  discard block
 block discarded – undo
145 145
 	 *
146 146
 	 * @param WordPoints_EntityishI $current_arg The current arg.
147 147
 	 */
148
-	protected function validate_conditions( $current_arg ) {
148
+	protected function validate_conditions($current_arg) {
149 149
 
150
-		$args = new WordPoints_Hook_Event_Args( array() );
150
+		$args = new WordPoints_Hook_Event_Args(array());
151 151
 
152
-		if ( $current_arg instanceof WordPoints_Entity_Array ) {
152
+		if ($current_arg instanceof WordPoints_Entity_Array) {
153 153
 
154 154
 			$entity = wordpoints_entities()->get(
155 155
 				$current_arg->get_entity_slug()
156 156
 			);
157 157
 
158
-			if ( $entity instanceof WordPoints_Entity ) {
159
-				$args->add_entity( $entity );
158
+			if ($entity instanceof WordPoints_Entity) {
159
+				$args->add_entity($entity);
160 160
 			}
161 161
 		}
162 162
 
163
-		$args->set_validator( $this->validator );
163
+		$args->set_validator($this->validator);
164 164
 
165
-		$this->validator->push_field( 'conditions' );
165
+		$this->validator->push_field('conditions');
166 166
 
167 167
 		$this->settings['conditions'] = $this->conditions_extension->validate_conditions(
168 168
 			$this->settings['conditions']
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	/**
176 176
 	 * @since 1.0.0
177 177
 	 */
178
-	public function is_met( array $settings, WordPoints_Hook_Event_Args $args ) {
178
+	public function is_met(array $settings, WordPoints_Hook_Event_Args $args) {
179 179
 
180 180
 		$this->settings = $settings;
181 181
 
@@ -183,16 +183,16 @@  discard block
 block discarded – undo
183 183
 
184 184
 		$entities = array();
185 185
 
186
-		if ( $arg instanceof WordPoints_Entity_Array ) {
186
+		if ($arg instanceof WordPoints_Entity_Array) {
187 187
 
188 188
 			$entities = $arg->get_the_entities();
189 189
 
190
-			if ( isset( $this->settings['conditions'] ) ) {
191
-				$entities = $this->filter_entities( $entities );
190
+			if (isset($this->settings['conditions'])) {
191
+				$entities = $this->filter_entities($entities);
192 192
 			}
193 193
 		}
194 194
 
195
-		return $this->check_count( count( $entities ) );
195
+		return $this->check_count(count($entities));
196 196
 	}
197 197
 
198 198
 	/**
@@ -204,20 +204,20 @@  discard block
 block discarded – undo
204 204
 	 *
205 205
 	 * @return WordPoints_Entity[] The entities that matched the sub-conditions.
206 206
 	 */
207
-	protected function filter_entities( $entities ) {
207
+	protected function filter_entities($entities) {
208 208
 
209
-		foreach ( $entities as $index => $entity ) {
209
+		foreach ($entities as $index => $entity) {
210 210
 
211
-			$event_args = new WordPoints_Hook_Event_Args( array() );
212
-			$event_args->add_entity( $entity );
211
+			$event_args = new WordPoints_Hook_Event_Args(array());
212
+			$event_args->add_entity($entity);
213 213
 
214 214
 			$matches = $this->conditions_extension->conditions_are_met(
215 215
 				$this->settings['conditions']
216 216
 				, $event_args
217 217
 			);
218 218
 
219
-			if ( ! $matches ) {
220
-				unset( $entities[ $index ] );
219
+			if ( ! $matches) {
220
+				unset($entities[$index]);
221 221
 			}
222 222
 		}
223 223
 
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 	 *
234 234
 	 * @return bool Whether the count met the requirements.
235 235
 	 */
236
-	protected function check_count( $count ) {
236
+	protected function check_count($count) {
237 237
 
238
-		if ( isset( $this->settings['max'] ) && $count > $this->settings['max'] ) {
238
+		if (isset($this->settings['max']) && $count > $this->settings['max']) {
239 239
 			return false;
240 240
 		}
241 241
 
242
-		if ( isset( $this->settings['min'] ) && $count < $this->settings['min'] ) {
242
+		if (isset($this->settings['min']) && $count < $this->settings['min']) {
243 243
 			return false;
244 244
 		}
245 245
 
Please login to merge, or discard this patch.
src/includes/classes/hook/reactor/points.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * @since 1.0.0
29 29
 	 */
30
-	protected $action_types = array( 'fire', 'reverse' );
30
+	protected $action_types = array('fire', 'reverse');
31 31
 
32 32
 	/**
33 33
 	 * @since 1.0.0
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	public function get_settings_fields() {
60 60
 
61
-		$this->settings_fields['points']['label'] = _x( 'Points', 'form label', 'wordpoints' );
62
-		$this->settings_fields['log_text']['label'] = _x( 'Log Text', 'form label', 'wordpoints' );
63
-		$this->settings_fields['description']['label'] = _x( 'Description', 'form label', 'wordpoints' );
61
+		$this->settings_fields['points']['label'] = _x('Points', 'form label', 'wordpoints');
62
+		$this->settings_fields['log_text']['label'] = _x('Log Text', 'form label', 'wordpoints');
63
+		$this->settings_fields['description']['label'] = _x('Description', 'form label', 'wordpoints');
64 64
 
65 65
 		return parent::get_settings_fields();
66 66
 	}
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 
73 73
 		$data = parent::get_ui_script_data();
74 74
 
75
-		$data['target_label'] = __( 'Award To', 'wordpoints' );
76
-		$data['periods_label'] = __( 'Award each user no more than once per:', 'wordpoints' );
75
+		$data['target_label'] = __('Award To', 'wordpoints');
76
+		$data['periods_label'] = __('Award each user no more than once per:', 'wordpoints');
77 77
 
78 78
 		return $data;
79 79
 	}
@@ -87,23 +87,23 @@  discard block
 block discarded – undo
87 87
 		WordPoints_Hook_Event_Args $event_args
88 88
 	) {
89 89
 
90
-		if ( ! isset( $settings['points'] ) || false === wordpoints_int( $settings['points'] ) ) {
91
-			$validator->add_error( __( 'Points must be an integer.', 'wordpoints' ), 'points' );
90
+		if ( ! isset($settings['points']) || false === wordpoints_int($settings['points'])) {
91
+			$validator->add_error(__('Points must be an integer.', 'wordpoints'), 'points');
92 92
 		}
93 93
 
94
-		if ( ! isset( $settings['points_type'] ) || ! wordpoints_is_points_type( $settings['points_type'] ) ) {
95
-			$validator->add_error( __( 'Invalid points type.', 'wordpoints' ), 'points_type' );
94
+		if ( ! isset($settings['points_type']) || ! wordpoints_is_points_type($settings['points_type'])) {
95
+			$validator->add_error(__('Invalid points type.', 'wordpoints'), 'points_type');
96 96
 		}
97 97
 
98
-		if ( ! isset( $settings['description'] ) ) {
99
-			$validator->add_error( __( 'Description is required.', 'wordpoints' ), 'description' );
98
+		if ( ! isset($settings['description'])) {
99
+			$validator->add_error(__('Description is required.', 'wordpoints'), 'description');
100 100
 		}
101 101
 
102
-		if ( ! isset( $settings['log_text'] ) ) {
103
-			$validator->add_error( __( 'Log Text is required.', 'wordpoints' ), 'log_text' );
102
+		if ( ! isset($settings['log_text'])) {
103
+			$validator->add_error(__('Log Text is required.', 'wordpoints'), 'log_text');
104 104
 		}
105 105
 
106
-		return parent::validate_settings( $settings, $validator, $event_args );
106
+		return parent::validate_settings($settings, $validator, $event_args);
107 107
 	}
108 108
 
109 109
 	/**
@@ -114,54 +114,54 @@  discard block
 block discarded – undo
114 114
 		array $settings
115 115
 	) {
116 116
 
117
-		parent::update_settings( $reaction, $settings );
117
+		parent::update_settings($reaction, $settings);
118 118
 
119
-		$reaction->update_meta( 'points', $settings['points'] );
120
-		$reaction->update_meta( 'points_type', $settings['points_type'] );
121
-		$reaction->update_meta( 'description', $settings['description'] );
122
-		$reaction->update_meta( 'log_text', $settings['log_text'] );
119
+		$reaction->update_meta('points', $settings['points']);
120
+		$reaction->update_meta('points_type', $settings['points_type']);
121
+		$reaction->update_meta('description', $settings['description']);
122
+		$reaction->update_meta('log_text', $settings['log_text']);
123 123
 	}
124 124
 
125 125
 	/**
126 126
 	 * @since 1.0.0
127 127
 	 */
128
-	public function hit( WordPoints_Hook_Fire $fire ) {
128
+	public function hit(WordPoints_Hook_Fire $fire) {
129 129
 
130
-		if ( 'reverse' === $fire->action_type ) {
131
-			$this->reverse_hit( $fire );
130
+		if ('reverse' === $fire->action_type) {
131
+			$this->reverse_hit($fire);
132 132
 			return;
133 133
 		}
134 134
 
135 135
 		$reaction = $fire->reaction;
136 136
 
137 137
 		$target = $fire->event_args->get_from_hierarchy(
138
-			$reaction->get_meta( 'target' )
138
+			$reaction->get_meta('target')
139 139
 		);
140 140
 
141
-		if ( ! $target instanceof WordPoints_Entity ) {
141
+		if ( ! $target instanceof WordPoints_Entity) {
142 142
 			return;
143 143
 		}
144 144
 
145 145
 		$meta = array();
146 146
 
147
-		foreach ( $fire->event_args->get_entities() as $entity ) {
148
-			$meta[ $entity->get_slug() ] = $entity->get_the_id();
147
+		foreach ($fire->event_args->get_entities() as $entity) {
148
+			$meta[$entity->get_slug()] = $entity->get_the_id();
149 149
 		}
150 150
 
151 151
 		wordpoints_alter_points(
152 152
 			$target->get_the_id()
153
-			, $reaction->get_meta( 'points' )
154
-			, $reaction->get_meta( 'points_type' )
153
+			, $reaction->get_meta('points')
154
+			, $reaction->get_meta('points_type')
155 155
 			, $reaction->get_event_slug()
156 156
 			, $meta
157
-			, $reaction->get_meta( 'log_text' )
157
+			, $reaction->get_meta('log_text')
158 158
 		);
159 159
 	}
160 160
 
161 161
 	/**
162 162
 	 * @since 1.0.0
163 163
 	 */
164
-	public function reverse_hit( WordPoints_Hook_Fire $fire ) {
164
+	public function reverse_hit(WordPoints_Hook_Fire $fire) {
165 165
 
166 166
 		$meta_queries = array(
167 167
 			array(
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			),
173 173
 		);
174 174
 
175
-		foreach ( $fire->event_args->get_entities() as $slug => $entity ) {
175
+		foreach ($fire->event_args->get_entities() as $slug => $entity) {
176 176
 
177 177
 			$meta_queries[] = array(
178 178
 				'key'   => $slug,
@@ -189,35 +189,35 @@  discard block
 block discarded – undo
189 189
 
190 190
 		$logs = $query->get();
191 191
 
192
-		if ( ! $logs ) {
192
+		if ( ! $logs) {
193 193
 			return;
194 194
 		}
195 195
 
196 196
 		global $wpdb;
197 197
 
198
-		add_filter( 'wordpoints_points_log', '__return_false' );
198
+		add_filter('wordpoints_points_log', '__return_false');
199 199
 
200
-		foreach ( $logs as $log ) {
200
+		foreach ($logs as $log) {
201 201
 
202 202
 			wordpoints_alter_points(
203 203
 				$log->user_id
204 204
 				, -$log->points
205 205
 				, $log->points_type
206 206
 				, "reverse-{$log->log_type}"
207
-				, array( 'original_log_id' => $log->id )
207
+				, array('original_log_id' => $log->id)
208 208
 			);
209 209
 
210
-			wordpoints_points_log_delete_all_metadata( $log->id );
210
+			wordpoints_points_log_delete_all_metadata($log->id);
211 211
 
212 212
 			// Now delete the log.
213 213
 			$wpdb->delete(
214 214
 				$wpdb->wordpoints_points_logs
215
-				, array( 'id' => $log->id )
215
+				, array('id' => $log->id)
216 216
 				, '%d'
217 217
 			); // WPCS: cache OK, cleaned by wordpoints_alter_points().
218 218
 		}
219 219
 
220
-		remove_filter( 'wordpoints_points_log', '__return_false' );
220
+		remove_filter('wordpoints_points_log', '__return_false');
221 221
 	}
222 222
 }
223 223
 
Please login to merge, or discard this patch.