Test Failed
Push — master ( f49c98...c5285d )
by Devin
01:02
created
includes/api/class-give-api.php 1 patch
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 * @uses   Give_API::invalid_key()
327 327
 	 * @uses   Give_API::invalid_auth()
328 328
 	 * @since  1.1
329
-	 * @return bool
329
+	 * @return false|null
330 330
 	 */
331 331
 	private function validate_request() {
332 332
 		global $wp_query;
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
 	 *
723 723
 	 * @param array $args Arguments to override defaults
724 724
 	 *
725
-	 * @return array $dates
725
+	 * @return integer|null $dates
726 726
 	 */
727 727
 	public function get_dates( $args = array() ) {
728 728
 		$dates = array();
Please login to merge, or discard this patch.
includes/forms/functions.php 1 patch
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
  *
156 156
  * Used to redirect a user back to the donation form if there are errors present.
157 157
  *
158
- * @param array|string $args
158
+ * @param string $args
159 159
  *
160 160
  * @access public
161 161
  * @since  1.0
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
  * @since  1.0
302 302
  * @since  1.8.16 Add security check
303 303
  *
304
- * @return bool
304
+ * @return false|null
305 305
  */
306 306
 function give_listen_for_failed_payments() {
307 307
 
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
  *
754 754
  * @param int $form_id ID number of the form to retrieve the minimum price for
755 755
  *
756
- * @return mixed string|int Minimum price of the form
756
+ * @return string string|int Minimum price of the form
757 757
  */
758 758
 function give_get_form_minimum_price( $form_id = 0 ) {
759 759
 
Please login to merge, or discard this patch.
includes/class-give-donate-form.php 1 patch
Spacing   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Exit if accessed directly.
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
 	 * @param  int|bool $_id   Post id. Default is false.
338 338
 	 * @param  array    $_args Arguments passed.
339 339
 	 */
340
-	public function __construct( $_id = false, $_args = array() ) {
340
+	public function __construct($_id = false, $_args = array()) {
341 341
 
342
-		$donation_form = WP_Post::get_instance( $_id );
342
+		$donation_form = WP_Post::get_instance($_id);
343 343
 
344
-		return $this->setup_donation_form( $donation_form );
344
+		return $this->setup_donation_form($donation_form);
345 345
 	}
346 346
 
347 347
 	/**
@@ -354,23 +354,23 @@  discard block
 block discarded – undo
354 354
 	 *
355 355
 	 * @return bool                   If the setup was successful or not.
356 356
 	 */
357
-	private function setup_donation_form( $donation_form ) {
357
+	private function setup_donation_form($donation_form) {
358 358
 
359
-		if ( ! is_object( $donation_form ) ) {
359
+		if ( ! is_object($donation_form)) {
360 360
 			return false;
361 361
 		}
362 362
 
363
-		if ( ! is_a( $donation_form, 'WP_Post' ) ) {
363
+		if ( ! is_a($donation_form, 'WP_Post')) {
364 364
 			return false;
365 365
 		}
366 366
 
367
-		if ( 'give_forms' !== $donation_form->post_type ) {
367
+		if ('give_forms' !== $donation_form->post_type) {
368 368
 			return false;
369 369
 		}
370 370
 
371
-		foreach ( $donation_form as $key => $value ) {
371
+		foreach ($donation_form as $key => $value) {
372 372
 
373
-			switch ( $key ) {
373
+			switch ($key) {
374 374
 
375 375
 				default:
376 376
 					$this->$key = $value;
@@ -394,16 +394,16 @@  discard block
 block discarded – undo
394 394
 	 *
395 395
 	 * @return mixed
396 396
 	 */
397
-	public function __get( $key ) {
397
+	public function __get($key) {
398 398
 
399
-		if ( method_exists( $this, 'get_' . $key ) ) {
399
+		if (method_exists($this, 'get_'.$key)) {
400 400
 
401
-			return call_user_func( array( $this, 'get_' . $key ) );
401
+			return call_user_func(array($this, 'get_'.$key));
402 402
 
403 403
 		} else {
404 404
 
405 405
 			/* translators: %s: property key */
406
-			return new WP_Error( 'give-form-invalid-property', sprintf( esc_html__( 'Can\'t get property %s.', 'give' ), $key ) );
406
+			return new WP_Error('give-form-invalid-property', sprintf(esc_html__('Can\'t get property %s.', 'give'), $key));
407 407
 
408 408
 		}
409 409
 
@@ -419,30 +419,30 @@  discard block
 block discarded – undo
419 419
 	 *
420 420
 	 * @return bool|int    False if data isn't passed and class not instantiated for creation, or New Form ID.
421 421
 	 */
422
-	public function create( $data = array() ) {
422
+	public function create($data = array()) {
423 423
 
424
-		if ( $this->id != 0 ) {
424
+		if ($this->id != 0) {
425 425
 			return false;
426 426
 		}
427 427
 
428 428
 		$defaults = array(
429 429
 			'post_type'   => 'give_forms',
430 430
 			'post_status' => 'draft',
431
-			'post_title'  => __( 'New Donation Form', 'give' ),
431
+			'post_title'  => __('New Donation Form', 'give'),
432 432
 		);
433 433
 
434
-		$args = wp_parse_args( $data, $defaults );
434
+		$args = wp_parse_args($data, $defaults);
435 435
 
436 436
 		/**
437 437
 		 * Fired before a donation form is created
438 438
 		 *
439 439
 		 * @param array $args The post object arguments used for creation.
440 440
 		 */
441
-		do_action( 'give_form_pre_create', $args );
441
+		do_action('give_form_pre_create', $args);
442 442
 
443
-		$id = wp_insert_post( $args, true );
443
+		$id = wp_insert_post($args, true);
444 444
 
445
-		$donation_form = WP_Post::get_instance( $id );
445
+		$donation_form = WP_Post::get_instance($id);
446 446
 
447 447
 		/**
448 448
 		 * Fired after a donation form is created
@@ -450,9 +450,9 @@  discard block
 block discarded – undo
450 450
 		 * @param int   $id   The post ID of the created item.
451 451
 		 * @param array $args The post object arguments used for creation.
452 452
 		 */
453
-		do_action( 'give_form_post_create', $id, $args );
453
+		do_action('give_form_post_create', $id, $args);
454 454
 
455
-		return $this->setup_donation_form( $donation_form );
455
+		return $this->setup_donation_form($donation_form);
456 456
 
457 457
 	}
458 458
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return string Donation form name.
478 478
 	 */
479 479
 	public function get_name() {
480
-		return get_the_title( $this->ID );
480
+		return get_the_title($this->ID);
481 481
 	}
482 482
 
483 483
 	/**
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 	 */
491 491
 	public function get_price() {
492 492
 
493
-		if ( ! isset( $this->price ) ) {
493
+		if ( ! isset($this->price)) {
494 494
 
495 495
 			$this->price = give_maybe_sanitize_amount(
496 496
 				give_get_meta(
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 				)
501 501
 			);
502 502
 
503
-			if ( ! $this->price ) {
503
+			if ( ! $this->price) {
504 504
 				$this->price = 0;
505 505
 			}
506 506
 
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 		 * @param string     $price The donation form price.
515 515
 		 * @param string|int $id    The form ID.
516 516
 		 */
517
-		return apply_filters( 'give_get_set_price', $this->price, $this->ID );
517
+		return apply_filters('give_get_set_price', $this->price, $this->ID);
518 518
 	}
519 519
 
520 520
 	/**
@@ -527,17 +527,17 @@  discard block
 block discarded – undo
527 527
 	 */
528 528
 	public function get_minimum_price() {
529 529
 
530
-		if ( ! isset( $this->minimum_price ) ) {
530
+		if ( ! isset($this->minimum_price)) {
531 531
 
532
-			$this->minimum_price = give_get_meta( $this->ID, '_give_custom_amount_minimum', true );
532
+			$this->minimum_price = give_get_meta($this->ID, '_give_custom_amount_minimum', true);
533 533
 
534
-			if ( ! $this->is_custom_price_mode() ) {
534
+			if ( ! $this->is_custom_price_mode()) {
535 535
 				$this->minimum_price = 0;
536 536
 			}
537 537
 
538 538
 		}
539 539
 
540
-		return apply_filters( 'give_get_set_minimum_price', $this->minimum_price, $this->ID );
540
+		return apply_filters('give_get_set_minimum_price', $this->minimum_price, $this->ID);
541 541
 	}
542 542
 
543 543
 	/**
@@ -550,9 +550,9 @@  discard block
 block discarded – undo
550 550
 	 */
551 551
 	public function get_prices() {
552 552
 
553
-		if ( ! isset( $this->prices ) ) {
553
+		if ( ! isset($this->prices)) {
554 554
 
555
-			$this->prices = give_get_meta( $this->ID, '_give_donation_levels', true );
555
+			$this->prices = give_get_meta($this->ID, '_give_donation_levels', true);
556 556
 
557 557
 		}
558 558
 
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
 		 * @param array      $prices The array of mulit-level prices.
565 565
 		 * @param int|string $ID     The ID of the form.
566 566
 		 */
567
-		return apply_filters( 'give_get_donation_levels', $this->prices, $this->ID );
567
+		return apply_filters('give_get_donation_levels', $this->prices, $this->ID);
568 568
 
569 569
 	}
570 570
 
@@ -578,21 +578,21 @@  discard block
 block discarded – undo
578 578
 	 */
579 579
 	public function get_goal() {
580 580
 
581
-		if ( ! isset( $this->goal ) ) {
581
+		if ( ! isset($this->goal)) {
582 582
 
583
-			if ( 'donation' === give_get_form_goal_format( $this->ID ) ) {
584
-				$this->goal = give_get_meta( $this->ID, '_give_number_of_donation_goal', true );
583
+			if ('donation' === give_get_form_goal_format($this->ID)) {
584
+				$this->goal = give_get_meta($this->ID, '_give_number_of_donation_goal', true);
585 585
 			} else {
586
-				$this->goal = give_get_meta( $this->ID, '_give_set_goal', true );
586
+				$this->goal = give_get_meta($this->ID, '_give_set_goal', true);
587 587
 			}
588 588
 
589
-			if ( ! $this->goal ) {
589
+			if ( ! $this->goal) {
590 590
 				$this->goal = 0;
591 591
 			}
592 592
 
593 593
 		}
594 594
 
595
-		return apply_filters( 'give_get_set_goal', $this->goal, $this->ID );
595
+		return apply_filters('give_get_set_goal', $this->goal, $this->ID);
596 596
 
597 597
 	}
598 598
 
@@ -606,10 +606,10 @@  discard block
 block discarded – undo
606 606
 	 */
607 607
 	public function is_single_price_mode() {
608 608
 
609
-		$option = give_get_meta( $this->ID, '_give_price_option', true );
609
+		$option = give_get_meta($this->ID, '_give_price_option', true);
610 610
 		$ret    = 0;
611 611
 
612
-		if ( empty( $option ) || $option === 'set' ) {
612
+		if (empty($option) || $option === 'set') {
613 613
 			$ret = 1;
614 614
 		}
615 615
 
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
 		 * @param bool       $ret Is donation form in single price mode?
622 622
 		 * @param int|string $ID The ID of the donation form.
623 623
 		 */
624
-		return (bool) apply_filters( 'give_single_price_option_mode', $ret, $this->ID );
624
+		return (bool) apply_filters('give_single_price_option_mode', $ret, $this->ID);
625 625
 
626 626
 	}
627 627
 
@@ -635,10 +635,10 @@  discard block
 block discarded – undo
635 635
 	 */
636 636
 	public function is_custom_price_mode() {
637 637
 
638
-		$option = give_get_meta( $this->ID, '_give_custom_amount', true );
638
+		$option = give_get_meta($this->ID, '_give_custom_amount', true);
639 639
 		$ret    = 0;
640 640
 
641
-		if ( give_is_setting_enabled( $option ) ) {
641
+		if (give_is_setting_enabled($option)) {
642 642
 			$ret = 1;
643 643
 		}
644 644
 
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 		 * @param bool       $ret Is donation form in custom price mode?
651 651
 		 * @param int|string $ID  The ID of the donation form.
652 652
 		 */
653
-		return (bool) apply_filters( 'give_custom_price_option_mode', $ret, $this->ID );
653
+		return (bool) apply_filters('give_custom_price_option_mode', $ret, $this->ID);
654 654
 
655 655
 	}
656 656
 
@@ -664,20 +664,20 @@  discard block
 block discarded – undo
664 664
 	 *
665 665
 	 * @return bool
666 666
 	 */
667
-	public function is_custom_price( $amount ) {
667
+	public function is_custom_price($amount) {
668 668
 		$result = false;
669
-		$amount = give_maybe_sanitize_amount( $amount );
669
+		$amount = give_maybe_sanitize_amount($amount);
670 670
 
671
-		if ( $this->is_custom_price_mode() ) {
671
+		if ($this->is_custom_price_mode()) {
672 672
 
673
-			if ( 'set' === $this->get_type() ) {
674
-				if ( $amount !== $this->get_price() ) {
673
+			if ('set' === $this->get_type()) {
674
+				if ($amount !== $this->get_price()) {
675 675
 					$result = true;
676 676
 				}
677 677
 
678
-			} elseif ( 'multi' === $this->get_type() ) {
679
-				$level_amounts = array_map( 'give_maybe_sanitize_amount', wp_list_pluck( $this->get_prices(), '_give_amount' ) );
680
-				$result        = ! in_array( $amount, $level_amounts );
678
+			} elseif ('multi' === $this->get_type()) {
679
+				$level_amounts = array_map('give_maybe_sanitize_amount', wp_list_pluck($this->get_prices(), '_give_amount'));
680
+				$result        = ! in_array($amount, $level_amounts);
681 681
 			}
682 682
 		}
683 683
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 		 *
691 691
 		 * @since 1.8.18
692 692
 		 */
693
-		return (bool) apply_filters( 'give_is_custom_price', $result, $amount, $this->ID );
693
+		return (bool) apply_filters('give_is_custom_price', $result, $amount, $this->ID);
694 694
 	}
695 695
 
696 696
 	/**
@@ -705,10 +705,10 @@  discard block
 block discarded – undo
705 705
 	 */
706 706
 	public function has_variable_prices() {
707 707
 
708
-		$option = give_get_meta( $this->ID, '_give_price_option', true );
708
+		$option = give_get_meta($this->ID, '_give_price_option', true);
709 709
 		$ret    = 0;
710 710
 
711
-		if ( $option === 'multi' ) {
711
+		if ($option === 'multi') {
712 712
 			$ret = 1;
713 713
 		}
714 714
 
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 		 * @param bool       $ret Does donation form have variable prices?
719 719
 		 * @param int|string $ID  The ID of the donation form.
720 720
 		 */
721
-		return (bool) apply_filters( 'give_has_variable_prices', $ret, $this->ID );
721
+		return (bool) apply_filters('give_has_variable_prices', $ret, $this->ID);
722 722
 
723 723
 	}
724 724
 
@@ -732,17 +732,17 @@  discard block
 block discarded – undo
732 732
 	 */
733 733
 	public function get_type() {
734 734
 
735
-		if ( ! isset( $this->type ) ) {
735
+		if ( ! isset($this->type)) {
736 736
 
737
-			$this->type = give_get_meta( $this->ID, '_give_price_option', true );
737
+			$this->type = give_get_meta($this->ID, '_give_price_option', true);
738 738
 
739
-			if ( empty( $this->type ) ) {
739
+			if (empty($this->type)) {
740 740
 				$this->type = 'set';
741 741
 			}
742 742
 
743 743
 		}
744 744
 
745
-		return apply_filters( 'give_get_form_type', $this->type, $this->ID );
745
+		return apply_filters('give_get_form_type', $this->type, $this->ID);
746 746
 
747 747
 	}
748 748
 
@@ -758,23 +758,23 @@  discard block
 block discarded – undo
758 758
 	 *
759 759
 	 * @return string
760 760
 	 */
761
-	public function get_form_classes( $args ) {
761
+	public function get_form_classes($args) {
762 762
 
763
-		$float_labels_option = give_is_float_labels_enabled( $args )
763
+		$float_labels_option = give_is_float_labels_enabled($args)
764 764
 			? 'float-labels-enabled'
765 765
 			: '';
766 766
 
767
-		$form_classes_array = apply_filters( 'give_form_classes', array(
767
+		$form_classes_array = apply_filters('give_form_classes', array(
768 768
 			'give-form',
769
-			'give-form-' . $this->ID,
770
-			'give-form-type-' . $this->get_type(),
769
+			'give-form-'.$this->ID,
770
+			'give-form-type-'.$this->get_type(),
771 771
 			$float_labels_option,
772
-		), $this->ID, $args );
772
+		), $this->ID, $args);
773 773
 
774 774
 		// Remove empty class names.
775
-		$form_classes_array = array_filter( $form_classes_array );
775
+		$form_classes_array = array_filter($form_classes_array);
776 776
 
777
-		return implode( ' ', $form_classes_array );
777
+		return implode(' ', $form_classes_array);
778 778
 
779 779
 	}
780 780
 
@@ -789,22 +789,22 @@  discard block
 block discarded – undo
789 789
 	 *
790 790
 	 * @return string
791 791
 	 */
792
-	public function get_form_wrap_classes( $args ) {
792
+	public function get_form_wrap_classes($args) {
793 793
 		$custom_class = array(
794 794
 			'give-form-wrap',
795 795
 		);
796 796
 
797
-		if ( $this->is_close_donation_form() ) {
797
+		if ($this->is_close_donation_form()) {
798 798
 			$custom_class[] = 'give-form-closed';
799
-		} else{
800
-			$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
799
+		} else {
800
+			$display_option = (isset($args['display_style']) && ! empty($args['display_style']))
801 801
 				? $args['display_style']
802
-				: give_get_meta( $this->ID, '_give_payment_display', true );
802
+				: give_get_meta($this->ID, '_give_payment_display', true);
803 803
 
804 804
 			$custom_class[] = "give-display-{$display_option}";
805 805
 
806 806
 			// If admin want to show only button for form then user inbuilt modal functionality.
807
-			if ( 'button' === $display_option ) {
807
+			if ('button' === $display_option) {
808 808
 				$custom_class[] = 'give-display-button-only';
809 809
 			}
810 810
 		}
@@ -815,10 +815,10 @@  discard block
 block discarded – undo
815 815
 		 *
816 816
 		 * @since 1.0
817 817
 		 */
818
-		$form_wrap_classes_array = (array) apply_filters( 'give_form_wrap_classes', $custom_class, $this->ID, $args );
818
+		$form_wrap_classes_array = (array) apply_filters('give_form_wrap_classes', $custom_class, $this->ID, $args);
819 819
 
820 820
 
821
-		return implode( ' ', $form_wrap_classes_array );
821
+		return implode(' ', $form_wrap_classes_array);
822 822
 
823 823
 	}
824 824
 
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 	public function is_set_type_donation_form() {
834 834
 		$form_type = $this->get_type();
835 835
 
836
-		return ( 'set' === $form_type ? true : false );
836
+		return ('set' === $form_type ? true : false);
837 837
 	}
838 838
 
839 839
 	/**
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 	public function is_multi_type_donation_form() {
848 848
 		$form_type = $this->get_type();
849 849
 
850
-		return ( 'multi' === $form_type ? true : false );
850
+		return ('multi' === $form_type ? true : false);
851 851
 
852 852
 	}
853 853
 
@@ -861,15 +861,15 @@  discard block
 block discarded – undo
861 861
 	 */
862 862
 	public function get_sales() {
863 863
 
864
-		if ( ! isset( $this->sales ) ) {
864
+		if ( ! isset($this->sales)) {
865 865
 
866
-			if ( '' == give_get_meta( $this->ID, '_give_form_sales', true ) ) {
867
-				add_post_meta( $this->ID, '_give_form_sales', 0 );
866
+			if ('' == give_get_meta($this->ID, '_give_form_sales', true)) {
867
+				add_post_meta($this->ID, '_give_form_sales', 0);
868 868
 			} // End if
869 869
 
870
-			$this->sales = give_get_meta( $this->ID, '_give_form_sales', true );
870
+			$this->sales = give_get_meta($this->ID, '_give_form_sales', true);
871 871
 
872
-			if ( $this->sales < 0 ) {
872
+			if ($this->sales < 0) {
873 873
 				// Never let sales be less than zero.
874 874
 				$this->sales = 0;
875 875
 			}
@@ -890,13 +890,13 @@  discard block
 block discarded – undo
890 890
 	 *
891 891
 	 * @return int|false     New number of total sales.
892 892
 	 */
893
-	public function increase_sales( $quantity = 1 ) {
893
+	public function increase_sales($quantity = 1) {
894 894
 
895
-		$sales       = give_get_form_sales_stats( $this->ID );
896
-		$quantity    = absint( $quantity );
895
+		$sales       = give_get_form_sales_stats($this->ID);
896
+		$quantity    = absint($quantity);
897 897
 		$total_sales = $sales + $quantity;
898 898
 
899
-		if ( $this->update_meta( '_give_form_sales', $total_sales ) ) {
899
+		if ($this->update_meta('_give_form_sales', $total_sales)) {
900 900
 
901 901
 			$this->sales = $total_sales;
902 902
 
@@ -917,17 +917,17 @@  discard block
 block discarded – undo
917 917
 	 *
918 918
 	 * @return int|false     New number of total sales.
919 919
 	 */
920
-	public function decrease_sales( $quantity = 1 ) {
920
+	public function decrease_sales($quantity = 1) {
921 921
 
922
-		$sales = give_get_form_sales_stats( $this->ID );
922
+		$sales = give_get_form_sales_stats($this->ID);
923 923
 
924 924
 		// Only decrease if not already zero
925
-		if ( $sales > 0 ) {
925
+		if ($sales > 0) {
926 926
 
927
-			$quantity    = absint( $quantity );
927
+			$quantity    = absint($quantity);
928 928
 			$total_sales = $sales - $quantity;
929 929
 
930
-			if ( $this->update_meta( '_give_form_sales', $total_sales ) ) {
930
+			if ($this->update_meta('_give_form_sales', $total_sales)) {
931 931
 
932 932
 				$this->sales = $sales;
933 933
 
@@ -951,15 +951,15 @@  discard block
 block discarded – undo
951 951
 	 */
952 952
 	public function get_earnings() {
953 953
 
954
-		if ( ! isset( $this->earnings ) ) {
954
+		if ( ! isset($this->earnings)) {
955 955
 
956
-			if ( '' == give_get_meta( $this->ID, '_give_form_earnings', true ) ) {
957
-				add_post_meta( $this->ID, '_give_form_earnings', 0 );
956
+			if ('' == give_get_meta($this->ID, '_give_form_earnings', true)) {
957
+				add_post_meta($this->ID, '_give_form_earnings', 0);
958 958
 			}
959 959
 
960
-			$this->earnings = give_get_meta( $this->ID, '_give_form_earnings', true );
960
+			$this->earnings = give_get_meta($this->ID, '_give_form_earnings', true);
961 961
 
962
-			if ( $this->earnings < 0 ) {
962
+			if ($this->earnings < 0) {
963 963
 				// Never let earnings be less than zero
964 964
 				$this->earnings = 0;
965 965
 			}
@@ -980,12 +980,12 @@  discard block
 block discarded – undo
980 980
 	 *
981 981
 	 * @return float|false
982 982
 	 */
983
-	public function increase_earnings( $amount = 0 ) {
983
+	public function increase_earnings($amount = 0) {
984 984
 
985
-		$earnings   = give_get_form_earnings_stats( $this->ID );
985
+		$earnings   = give_get_form_earnings_stats($this->ID);
986 986
 		$new_amount = $earnings + (float) $amount;
987 987
 
988
-		if ( $this->update_meta( '_give_form_earnings', $new_amount ) ) {
988
+		if ($this->update_meta('_give_form_earnings', $new_amount)) {
989 989
 
990 990
 			$this->earnings = $new_amount;
991 991
 
@@ -1007,16 +1007,16 @@  discard block
 block discarded – undo
1007 1007
 	 *
1008 1008
 	 * @return float|false
1009 1009
 	 */
1010
-	public function decrease_earnings( $amount ) {
1010
+	public function decrease_earnings($amount) {
1011 1011
 
1012
-		$earnings = give_get_form_earnings_stats( $this->ID );
1012
+		$earnings = give_get_form_earnings_stats($this->ID);
1013 1013
 
1014
-		if ( $earnings > 0 ) {
1014
+		if ($earnings > 0) {
1015 1015
 			// Only decrease if greater than zero
1016 1016
 			$new_amount = $earnings - (float) $amount;
1017 1017
 
1018 1018
 
1019
-			if ( $this->update_meta( '_give_form_earnings', $new_amount ) ) {
1019
+			if ($this->update_meta('_give_form_earnings', $new_amount)) {
1020 1020
 
1021 1021
 				$this->earnings = $new_amount;
1022 1022
 
@@ -1040,22 +1040,22 @@  discard block
 block discarded – undo
1040 1040
 	 *
1041 1041
 	 * @return bool
1042 1042
 	 */
1043
-	public function is_free( $price_id = false ) {
1043
+	public function is_free($price_id = false) {
1044 1044
 
1045 1045
 		$is_free          = false;
1046
-		$variable_pricing = give_has_variable_prices( $this->ID );
1046
+		$variable_pricing = give_has_variable_prices($this->ID);
1047 1047
 
1048
-		if ( $variable_pricing && ! is_null( $price_id ) && $price_id !== false ) {
1049
-			$price = give_get_price_option_amount( $this->ID, $price_id );
1050
-		} elseif ( ! $variable_pricing ) {
1051
-			$price = give_get_meta( $this->ID, '_give_set_price', true );
1048
+		if ($variable_pricing && ! is_null($price_id) && $price_id !== false) {
1049
+			$price = give_get_price_option_amount($this->ID, $price_id);
1050
+		} elseif ( ! $variable_pricing) {
1051
+			$price = give_get_meta($this->ID, '_give_set_price', true);
1052 1052
 		}
1053 1053
 
1054
-		if ( isset( $price ) && (float) $price == 0 ) {
1054
+		if (isset($price) && (float) $price == 0) {
1055 1055
 			$is_free = true;
1056 1056
 		}
1057 1057
 
1058
-		return (bool) apply_filters( 'give_is_free_donation', $is_free, $this->ID, $price_id );
1058
+		return (bool) apply_filters('give_is_free_donation', $is_free, $this->ID, $price_id);
1059 1059
 
1060 1060
 	}
1061 1061
 
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 	 */
1075 1075
 	public function is_close_donation_form() {
1076 1076
 
1077
-		$goal_format = give_get_form_goal_format( $this->ID );
1077
+		$goal_format = give_get_form_goal_format($this->ID);
1078 1078
 
1079 1079
 		/**
1080 1080
 		 * Filter the close form result.
@@ -1084,9 +1084,9 @@  discard block
 block discarded – undo
1084 1084
 		$is_close_form = apply_filters(
1085 1085
 			'give_is_close_donation_form',
1086 1086
 			(
1087
-				give_is_setting_enabled( give_get_meta( $this->ID, '_give_goal_option', true ) ) &&
1088
-				give_is_setting_enabled( give_get_meta( $this->ID, '_give_close_form_when_goal_achieved', true ) ) &&
1089
-				( 'donation' === $goal_format ? $this->get_goal() <= $this->get_sales() : $this->get_goal() <= $this->get_earnings() )
1087
+				give_is_setting_enabled(give_get_meta($this->ID, '_give_goal_option', true)) &&
1088
+				give_is_setting_enabled(give_get_meta($this->ID, '_give_close_form_when_goal_achieved', true)) &&
1089
+				('donation' === $goal_format ? $this->get_goal() <= $this->get_sales() : $this->get_goal() <= $this->get_earnings())
1090 1090
 			),
1091 1091
 			$this->ID
1092 1092
 		);
@@ -1105,17 +1105,17 @@  discard block
 block discarded – undo
1105 1105
 	 *
1106 1106
 	 * @return bool                            The result of the update query.
1107 1107
 	 */
1108
-	private function update_meta( $meta_key = '', $meta_value = '' ) {
1108
+	private function update_meta($meta_key = '', $meta_value = '') {
1109 1109
 
1110 1110
 		/* @var WPDB $wpdb */
1111 1111
 		global $wpdb;
1112 1112
 
1113 1113
 		// Bailout.
1114
-		if ( empty( $meta_key ) ) {
1114
+		if (empty($meta_key)) {
1115 1115
 			return false;
1116 1116
 		}
1117 1117
 
1118
-		if ( give_update_meta( $this->ID, $meta_key, $meta_value  ) ) {
1118
+		if (give_update_meta($this->ID, $meta_key, $meta_value)) {
1119 1119
 			return true;
1120 1120
 		}
1121 1121
 
Please login to merge, or discard this patch.
includes/class-give-donor.php 1 patch
Spacing   +253 added lines, -260 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Exit if accessed directly.
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -149,32 +149,32 @@  discard block
 block discarded – undo
149 149
 	 * @param int|bool $_id_or_email
150 150
 	 * @param bool     $by_user_id
151 151
 	 */
152
-	public function __construct( $_id_or_email = false, $by_user_id = false ) {
152
+	public function __construct($_id_or_email = false, $by_user_id = false) {
153 153
 
154 154
 		$this->db = Give()->donors;
155 155
 
156 156
 		if (
157 157
 			false === $_id_or_email
158
-			|| ( is_numeric( $_id_or_email ) && (int) $_id_or_email !== absint( $_id_or_email ) )
158
+			|| (is_numeric($_id_or_email) && (int) $_id_or_email !== absint($_id_or_email))
159 159
 		) {
160 160
 			return false;
161 161
 		}
162 162
 
163
-		$by_user_id = is_bool( $by_user_id ) ? $by_user_id : false;
163
+		$by_user_id = is_bool($by_user_id) ? $by_user_id : false;
164 164
 
165
-		if ( is_numeric( $_id_or_email ) ) {
165
+		if (is_numeric($_id_or_email)) {
166 166
 			$field = $by_user_id ? 'user_id' : 'id';
167 167
 		} else {
168 168
 			$field = 'email';
169 169
 		}
170 170
 
171
-		$donor = $this->db->get_donor_by( $field, $_id_or_email );
171
+		$donor = $this->db->get_donor_by($field, $_id_or_email);
172 172
 
173
-		if ( empty( $donor ) || ! is_object( $donor ) ) {
173
+		if (empty($donor) || ! is_object($donor)) {
174 174
 			return false;
175 175
 		}
176 176
 
177
-		$this->setup_donor( $donor );
177
+		$this->setup_donor($donor);
178 178
 
179 179
 	}
180 180
 
@@ -190,19 +190,19 @@  discard block
 block discarded – undo
190 190
 	 *
191 191
 	 * @return bool             If the setup was successful or not.
192 192
 	 */
193
-	private function setup_donor( $donor ) {
193
+	private function setup_donor($donor) {
194 194
 
195
-		if ( ! is_object( $donor ) ) {
195
+		if ( ! is_object($donor)) {
196 196
 			return false;
197 197
 		}
198 198
 
199 199
 		// Get cached donors.
200
-		$donor_vars = Give_Cache::get_group( $donor->id, 'give-donors' );
200
+		$donor_vars = Give_Cache::get_group($donor->id, 'give-donors');
201 201
 
202
-		if( is_null( $donor_vars ) ){
203
-			foreach ( $donor as $key => $value ) {
202
+		if (is_null($donor_vars)) {
203
+			foreach ($donor as $key => $value) {
204 204
 
205
-				switch ( $key ) {
205
+				switch ($key) {
206 206
 
207 207
 					case 'notes':
208 208
 						$this->$key = $this->get_notes();
@@ -216,20 +216,20 @@  discard block
 block discarded – undo
216 216
 			}
217 217
 
218 218
 			// Get donor's all email including primary email.
219
-			$this->emails = (array) $this->get_meta( 'additional_email', false );
220
-			$this->emails = array( 'primary' => $this->email ) + $this->emails;
219
+			$this->emails = (array) $this->get_meta('additional_email', false);
220
+			$this->emails = array('primary' => $this->email) + $this->emails;
221 221
 
222 222
 			$this->setup_address();
223 223
 
224
-			Give_Cache::set_group( $donor->id, get_object_vars( $this ), 'give-donors' );
225
-		} else{
226
-			foreach ( $donor_vars as $donor_var => $value ) {
224
+			Give_Cache::set_group($donor->id, get_object_vars($this), 'give-donors');
225
+		} else {
226
+			foreach ($donor_vars as $donor_var => $value) {
227 227
 				$this->$donor_var = $value;
228 228
 			}
229 229
 		}
230 230
 
231 231
 		// Donor ID and email are the only things that are necessary, make sure they exist.
232
-		if ( ! empty( $this->id ) && ! empty( $this->email ) ) {
232
+		if ( ! empty($this->id) && ! empty($this->email)) {
233 233
 			return true;
234 234
 		}
235 235
 
@@ -262,18 +262,18 @@  discard block
 block discarded – undo
262 262
 			ARRAY_N
263 263
 		);
264 264
 
265
-		if ( empty( $addresses ) ) {
265
+		if (empty($addresses)) {
266 266
 			return $this->address;
267 267
 		}
268 268
 
269
-		foreach ( $addresses as $address ) {
270
-			$address[0] = str_replace( '_give_donor_address_', '', $address[0] );
271
-			$address[0] = explode( '_', $address[0] );
269
+		foreach ($addresses as $address) {
270
+			$address[0] = str_replace('_give_donor_address_', '', $address[0]);
271
+			$address[0] = explode('_', $address[0]);
272 272
 
273
-			if ( 3 === count( $address[0] ) ) {
274
-				$this->address[ $address[0][0] ][ $address[0][2] ][ $address[0][1] ] = $address[1];
273
+			if (3 === count($address[0])) {
274
+				$this->address[$address[0][0]][$address[0][2]][$address[0][1]] = $address[1];
275 275
 			} else {
276
-				$this->address[ $address[0][0] ][ $address[0][1] ] = $address[1];
276
+				$this->address[$address[0][0]][$address[0][1]] = $address[1];
277 277
 			}
278 278
 		}
279 279
 	}
@@ -287,16 +287,16 @@  discard block
 block discarded – undo
287 287
 	 *
288 288
 	 * @return mixed|\WP_Error
289 289
 	 */
290
-	public function __get( $key ) {
290
+	public function __get($key) {
291 291
 
292
-		if ( method_exists( $this, 'get_' . $key ) ) {
292
+		if (method_exists($this, 'get_'.$key)) {
293 293
 
294
-			return call_user_func( array( $this, 'get_' . $key ) );
294
+			return call_user_func(array($this, 'get_'.$key));
295 295
 
296 296
 		} else {
297 297
 
298 298
 			/* translators: %s: property key */
299
-			return new WP_Error( 'give-donor-invalid-property', sprintf( esc_html__( 'Can\'t get property %s.', 'give' ), $key ) );
299
+			return new WP_Error('give-donor-invalid-property', sprintf(esc_html__('Can\'t get property %s.', 'give'), $key));
300 300
 
301 301
 		}
302 302
 
@@ -312,9 +312,9 @@  discard block
 block discarded – undo
312 312
 	 *
313 313
 	 * @return bool|int    False if not a valid creation, donor ID if user is found or valid creation.
314 314
 	 */
315
-	public function create( $data = array() ) {
315
+	public function create($data = array()) {
316 316
 
317
-		if ( $this->id != 0 || empty( $data ) ) {
317
+		if ($this->id != 0 || empty($data)) {
318 318
 			return false;
319 319
 		}
320 320
 
@@ -322,15 +322,15 @@  discard block
 block discarded – undo
322 322
 			'payment_ids' => '',
323 323
 		);
324 324
 
325
-		$args = wp_parse_args( $data, $defaults );
326
-		$args = $this->sanitize_columns( $args );
325
+		$args = wp_parse_args($data, $defaults);
326
+		$args = $this->sanitize_columns($args);
327 327
 
328
-		if ( empty( $args['email'] ) || ! is_email( $args['email'] ) ) {
328
+		if (empty($args['email']) || ! is_email($args['email'])) {
329 329
 			return false;
330 330
 		}
331 331
 
332
-		if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) {
333
-			$args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) );
332
+		if ( ! empty($args['payment_ids']) && is_array($args['payment_ids'])) {
333
+			$args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids'])));
334 334
 		}
335 335
 
336 336
 		/**
@@ -340,18 +340,18 @@  discard block
 block discarded – undo
340 340
 		 *
341 341
 		 * @param array $args Donor attributes.
342 342
 		 */
343
-		do_action( 'give_donor_pre_create', $args );
343
+		do_action('give_donor_pre_create', $args);
344 344
 
345 345
 		$created = false;
346 346
 
347 347
 		// The DB class 'add' implies an update if the donor being asked to be created already exists
348
-		if ( $this->db->add( $data ) ) {
348
+		if ($this->db->add($data)) {
349 349
 
350 350
 			// We've successfully added/updated the donor, reset the class vars with the new data
351
-			$donor = $this->db->get_donor_by( 'email', $args['email'] );
351
+			$donor = $this->db->get_donor_by('email', $args['email']);
352 352
 
353 353
 			// Setup the donor data with the values from DB
354
-			$this->setup_donor( $donor );
354
+			$this->setup_donor($donor);
355 355
 
356 356
 			$created = $this->id;
357 357
 		}
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 		 * @param bool|int $created False if not a valid creation, donor ID if user is found or valid creation.
365 365
 		 * @param array $args Customer attributes.
366 366
 		 */
367
-		do_action( 'give_donor_post_create', $created, $args );
367
+		do_action('give_donor_post_create', $created, $args);
368 368
 
369 369
 		return $created;
370 370
 
@@ -380,13 +380,13 @@  discard block
 block discarded – undo
380 380
 	 *
381 381
 	 * @return bool        If the update was successful or not.
382 382
 	 */
383
-	public function update( $data = array() ) {
383
+	public function update($data = array()) {
384 384
 
385
-		if ( empty( $data ) ) {
385
+		if (empty($data)) {
386 386
 			return false;
387 387
 		}
388 388
 
389
-		$data = $this->sanitize_columns( $data );
389
+		$data = $this->sanitize_columns($data);
390 390
 
391 391
 		/**
392 392
 		 * Fires before updating donors.
@@ -396,15 +396,15 @@  discard block
 block discarded – undo
396 396
 		 * @param int $donor_id Donor id.
397 397
 		 * @param array $data Donor attributes.
398 398
 		 */
399
-		do_action( 'give_donor_pre_update', $this->id, $data );
399
+		do_action('give_donor_pre_update', $this->id, $data);
400 400
 
401 401
 		$updated = false;
402 402
 
403
-		if ( $this->db->update( $this->id, $data ) ) {
403
+		if ($this->db->update($this->id, $data)) {
404 404
 
405
-			$donor = $this->db->get_donor_by( 'id', $this->id );
405
+			$donor = $this->db->get_donor_by('id', $this->id);
406 406
 
407
-			$this->setup_donor( $donor );
407
+			$this->setup_donor($donor);
408 408
 
409 409
 			$updated = true;
410 410
 		}
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 		 * @param int $donor_id Donor id.
419 419
 		 * @param array $data Donor attributes.
420 420
 		 */
421
-		do_action( 'give_donor_post_update', $updated, $this->id, $data );
421
+		do_action('give_donor_post_update', $updated, $this->id, $data);
422 422
 
423 423
 		return $updated;
424 424
 	}
@@ -436,27 +436,27 @@  discard block
 block discarded – undo
436 436
 	 *
437 437
 	 * @return bool            If the attachment was successfully.
438 438
 	 */
439
-	public function attach_payment( $payment_id = 0, $update_stats = true ) {
439
+	public function attach_payment($payment_id = 0, $update_stats = true) {
440 440
 
441
-		if ( empty( $payment_id ) ) {
441
+		if (empty($payment_id)) {
442 442
 			return false;
443 443
 		}
444 444
 
445
-		if ( empty( $this->payment_ids ) ) {
445
+		if (empty($this->payment_ids)) {
446 446
 
447 447
 			$new_payment_ids = $payment_id;
448 448
 
449 449
 		} else {
450 450
 
451
-			$payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) );
451
+			$payment_ids = array_map('absint', explode(',', $this->payment_ids));
452 452
 
453
-			if ( in_array( $payment_id, $payment_ids ) ) {
453
+			if (in_array($payment_id, $payment_ids)) {
454 454
 				$update_stats = false;
455 455
 			}
456 456
 
457 457
 			$payment_ids[] = $payment_id;
458 458
 
459
-			$new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
459
+			$new_payment_ids = implode(',', array_unique(array_values($payment_ids)));
460 460
 
461 461
 		}
462 462
 
@@ -468,20 +468,20 @@  discard block
 block discarded – undo
468 468
 		 * @param int $payment_id Payment id.
469 469
 		 * @param int $donor_id Customer id.
470 470
 		 */
471
-		do_action( 'give_donor_pre_attach_payment', $payment_id, $this->id );
471
+		do_action('give_donor_pre_attach_payment', $payment_id, $this->id);
472 472
 
473
-		$payment_added = $this->update( array( 'payment_ids' => $new_payment_ids ) );
473
+		$payment_added = $this->update(array('payment_ids' => $new_payment_ids));
474 474
 
475
-		if ( $payment_added ) {
475
+		if ($payment_added) {
476 476
 
477 477
 			$this->payment_ids = $new_payment_ids;
478 478
 
479 479
 			// We added this payment successfully, increment the stats
480
-			if ( $update_stats ) {
481
-				$payment_amount = give_donation_amount( $payment_id, array( 'type' => 'stats' ) );
480
+			if ($update_stats) {
481
+				$payment_amount = give_donation_amount($payment_id, array('type' => 'stats'));
482 482
 
483
-				if ( ! empty( $payment_amount ) ) {
484
-					$this->increase_value( $payment_amount );
483
+				if ( ! empty($payment_amount)) {
484
+					$this->increase_value($payment_amount);
485 485
 				}
486 486
 
487 487
 				$this->increase_purchase_count();
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 		 * @param int $payment_id Payment id.
498 498
 		 * @param int $donor_id Donor id.
499 499
 		 */
500
-		do_action( 'give_donor_post_attach_payment', $payment_added, $payment_id, $this->id );
500
+		do_action('give_donor_post_attach_payment', $payment_added, $payment_id, $this->id);
501 501
 
502 502
 		return $payment_added;
503 503
 	}
@@ -515,33 +515,33 @@  discard block
 block discarded – undo
515 515
 	 *
516 516
 	 * @return boolean               If the removal was successful.
517 517
 	 */
518
-	public function remove_payment( $payment_id = 0, $update_stats = true ) {
518
+	public function remove_payment($payment_id = 0, $update_stats = true) {
519 519
 
520
-		if ( empty( $payment_id ) ) {
520
+		if (empty($payment_id)) {
521 521
 			return false;
522 522
 		}
523 523
 
524
-		$payment = new Give_Payment( $payment_id );
524
+		$payment = new Give_Payment($payment_id);
525 525
 
526
-		if ( 'publish' !== $payment->status && 'revoked' !== $payment->status ) {
526
+		if ('publish' !== $payment->status && 'revoked' !== $payment->status) {
527 527
 			$update_stats = false;
528 528
 		}
529 529
 
530 530
 		$new_payment_ids = '';
531 531
 
532
-		if ( ! empty( $this->payment_ids ) ) {
532
+		if ( ! empty($this->payment_ids)) {
533 533
 
534
-			$payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) );
534
+			$payment_ids = array_map('absint', explode(',', $this->payment_ids));
535 535
 
536
-			$pos = array_search( $payment_id, $payment_ids );
537
-			if ( false === $pos ) {
536
+			$pos = array_search($payment_id, $payment_ids);
537
+			if (false === $pos) {
538 538
 				return false;
539 539
 			}
540 540
 
541
-			unset( $payment_ids[ $pos ] );
542
-			$payment_ids = array_filter( $payment_ids );
541
+			unset($payment_ids[$pos]);
542
+			$payment_ids = array_filter($payment_ids);
543 543
 
544
-			$new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
544
+			$new_payment_ids = implode(',', array_unique(array_values($payment_ids)));
545 545
 
546 546
 		}
547 547
 
@@ -553,20 +553,20 @@  discard block
 block discarded – undo
553 553
 		 * @param int $payment_id Payment id.
554 554
 		 * @param int $donor_id Customer id.
555 555
 		 */
556
-		do_action( 'give_donor_pre_remove_payment', $payment_id, $this->id );
556
+		do_action('give_donor_pre_remove_payment', $payment_id, $this->id);
557 557
 
558
-		$payment_removed = $this->update( array( 'payment_ids' => $new_payment_ids ) );
558
+		$payment_removed = $this->update(array('payment_ids' => $new_payment_ids));
559 559
 
560
-		if ( $payment_removed ) {
560
+		if ($payment_removed) {
561 561
 
562 562
 			$this->payment_ids = $new_payment_ids;
563 563
 
564
-			if ( $update_stats ) {
564
+			if ($update_stats) {
565 565
 				// We removed this payment successfully, decrement the stats
566
-				$payment_amount = give_donation_amount( $payment_id );
566
+				$payment_amount = give_donation_amount($payment_id);
567 567
 
568
-				if ( ! empty( $payment_amount ) ) {
569
-					$this->decrease_value( $payment_amount );
568
+				if ( ! empty($payment_amount)) {
569
+					$this->decrease_value($payment_amount);
570 570
 				}
571 571
 
572 572
 				$this->decrease_donation_count();
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 		 * @param int $payment_id Payment id.
583 583
 		 * @param int $donor_id Donor id.
584 584
 		 */
585
-		do_action( 'give_donor_post_remove_payment', $payment_removed, $payment_id, $this->id );
585
+		do_action('give_donor_post_remove_payment', $payment_removed, $payment_id, $this->id);
586 586
 
587 587
 		return $payment_removed;
588 588
 
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
 	 *
599 599
 	 * @return int        The donation count.
600 600
 	 */
601
-	public function increase_purchase_count( $count = 1 ) {
601
+	public function increase_purchase_count($count = 1) {
602 602
 
603 603
 		// Make sure it's numeric and not negative.
604
-		if ( ! is_numeric( $count ) || $count != absint( $count ) ) {
604
+		if ( ! is_numeric($count) || $count != absint($count)) {
605 605
 			return false;
606 606
 		}
607 607
 
@@ -615,9 +615,9 @@  discard block
 block discarded – undo
615 615
 		 * @param int $count The number to increase by.
616 616
 		 * @param int $donor_id Donor id.
617 617
 		 */
618
-		do_action( 'give_donor_pre_increase_donation_count', $count, $this->id );
618
+		do_action('give_donor_pre_increase_donation_count', $count, $this->id);
619 619
 
620
-		if ( $this->update( array( 'purchase_count' => $new_total ) ) ) {
620
+		if ($this->update(array('purchase_count' => $new_total))) {
621 621
 			$this->purchase_count = $new_total;
622 622
 		}
623 623
 
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 		 * @param int $count The number increased by.
631 631
 		 * @param int $donor_id Donor id.
632 632
 		 */
633
-		do_action( 'give_donor_post_increase_donation_count', $this->purchase_count, $count, $this->id );
633
+		do_action('give_donor_post_increase_donation_count', $this->purchase_count, $count, $this->id);
634 634
 
635 635
 		return $this->purchase_count;
636 636
 	}
@@ -645,16 +645,16 @@  discard block
 block discarded – undo
645 645
 	 *
646 646
 	 * @return mixed      If successful, the new count, otherwise false.
647 647
 	 */
648
-	public function decrease_donation_count( $count = 1 ) {
648
+	public function decrease_donation_count($count = 1) {
649 649
 
650 650
 		// Make sure it's numeric and not negative
651
-		if ( ! is_numeric( $count ) || $count != absint( $count ) ) {
651
+		if ( ! is_numeric($count) || $count != absint($count)) {
652 652
 			return false;
653 653
 		}
654 654
 
655 655
 		$new_total = (int) $this->purchase_count - (int) $count;
656 656
 
657
-		if ( $new_total < 0 ) {
657
+		if ($new_total < 0) {
658 658
 			$new_total = 0;
659 659
 		}
660 660
 
@@ -666,9 +666,9 @@  discard block
 block discarded – undo
666 666
 		 * @param int $count The number to decrease by.
667 667
 		 * @param int $donor_id Customer id.
668 668
 		 */
669
-		do_action( 'give_donor_pre_decrease_donation_count', $count, $this->id );
669
+		do_action('give_donor_pre_decrease_donation_count', $count, $this->id);
670 670
 
671
-		if ( $this->update( array( 'purchase_count' => $new_total ) ) ) {
671
+		if ($this->update(array('purchase_count' => $new_total))) {
672 672
 			$this->purchase_count = $new_total;
673 673
 		}
674 674
 
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 		 * @param int $count The number decreased by.
682 682
 		 * @param int $donor_id Donor id.
683 683
 		 */
684
-		do_action( 'give_donor_post_decrease_donation_count', $this->purchase_count, $count, $this->id );
684
+		do_action('give_donor_post_decrease_donation_count', $this->purchase_count, $count, $this->id);
685 685
 
686 686
 		return $this->purchase_count;
687 687
 	}
@@ -696,9 +696,9 @@  discard block
 block discarded – undo
696 696
 	 *
697 697
 	 * @return mixed        If successful, the new value, otherwise false.
698 698
 	 */
699
-	public function increase_value( $value = 0.00 ) {
699
+	public function increase_value($value = 0.00) {
700 700
 
701
-		$new_value = floatval( $this->purchase_value ) + $value;
701
+		$new_value = floatval($this->purchase_value) + $value;
702 702
 
703 703
 		/**
704 704
 		 * Fires before increasing donor lifetime value.
@@ -708,9 +708,9 @@  discard block
 block discarded – undo
708 708
 		 * @param float $value The value to increase by.
709 709
 		 * @param int $donor_id Customer id.
710 710
 		 */
711
-		do_action( 'give_donor_pre_increase_value', $value, $this->id );
711
+		do_action('give_donor_pre_increase_value', $value, $this->id);
712 712
 
713
-		if ( $this->update( array( 'purchase_value' => $new_value ) ) ) {
713
+		if ($this->update(array('purchase_value' => $new_value))) {
714 714
 			$this->purchase_value = $new_value;
715 715
 		}
716 716
 
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 		 * @param float $value The value increased by.
724 724
 		 * @param int $donor_id Donor id.
725 725
 		 */
726
-		do_action( 'give_donor_post_increase_value', $this->purchase_value, $value, $this->id );
726
+		do_action('give_donor_post_increase_value', $this->purchase_value, $value, $this->id);
727 727
 
728 728
 		return $this->purchase_value;
729 729
 	}
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
 	 *
739 739
 	 * @return mixed        If successful, the new value, otherwise false.
740 740
 	 */
741
-	public function decrease_value( $value = 0.00 ) {
741
+	public function decrease_value($value = 0.00) {
742 742
 
743
-		$new_value = floatval( $this->purchase_value ) - $value;
743
+		$new_value = floatval($this->purchase_value) - $value;
744 744
 
745
-		if ( $new_value < 0 ) {
745
+		if ($new_value < 0) {
746 746
 			$new_value = 0.00;
747 747
 		}
748 748
 
@@ -754,9 +754,9 @@  discard block
 block discarded – undo
754 754
 		 * @param float $value The value to decrease by.
755 755
 		 * @param int $donor_id Donor id.
756 756
 		 */
757
-		do_action( 'give_donor_pre_decrease_value', $value, $this->id );
757
+		do_action('give_donor_pre_decrease_value', $value, $this->id);
758 758
 
759
-		if ( $this->update( array( 'purchase_value' => $new_value ) ) ) {
759
+		if ($this->update(array('purchase_value' => $new_value))) {
760 760
 			$this->purchase_value = $new_value;
761 761
 		}
762 762
 
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 		 * @param float $value The value decreased by.
770 770
 		 * @param int $donor_id Donor id.
771 771
 		 */
772
-		do_action( 'give_donor_post_decrease_value', $this->purchase_value, $value, $this->id );
772
+		do_action('give_donor_post_decrease_value', $this->purchase_value, $value, $this->id);
773 773
 
774 774
 		return $this->purchase_value;
775 775
 	}
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 	 *
789 789
 	 * @return mixed              If successful, the new donation stat value, otherwise false.
790 790
 	 */
791
-	public function update_donation_value( $curr_amount, $new_amount ) {
791
+	public function update_donation_value($curr_amount, $new_amount) {
792 792
 		/**
793 793
 		 * Payment total difference value can be:
794 794
 		 *  zero   (in case amount not change)
@@ -798,15 +798,15 @@  discard block
 block discarded – undo
798 798
 		$payment_total_diff = $new_amount - $curr_amount;
799 799
 
800 800
 		// We do not need to update donation stat if donation did not change.
801
-		if ( ! $payment_total_diff ) {
801
+		if ( ! $payment_total_diff) {
802 802
 			return false;
803 803
 		}
804 804
 
805
-		if ( $payment_total_diff > 0 ) {
806
-			$this->increase_value( $payment_total_diff );
805
+		if ($payment_total_diff > 0) {
806
+			$this->increase_value($payment_total_diff);
807 807
 		} else {
808 808
 			// Pass payment total difference as +ve value to decrease amount from user lifetime stat.
809
-			$this->decrease_value( - $payment_total_diff );
809
+			$this->decrease_value( -$payment_total_diff );
810 810
 		}
811 811
 
812 812
 		return $this->purchase_value;
@@ -823,15 +823,15 @@  discard block
 block discarded – undo
823 823
 	 *
824 824
 	 * @return array       The notes requested.
825 825
 	 */
826
-	public function get_notes( $length = 20, $paged = 1 ) {
826
+	public function get_notes($length = 20, $paged = 1) {
827 827
 
828
-		$length = is_numeric( $length ) ? $length : 20;
829
-		$offset = is_numeric( $paged ) && $paged != 1 ? ( ( absint( $paged ) - 1 ) * $length ) : 0;
828
+		$length = is_numeric($length) ? $length : 20;
829
+		$offset = is_numeric($paged) && $paged != 1 ? ((absint($paged) - 1) * $length) : 0;
830 830
 
831 831
 		$all_notes   = $this->get_raw_notes();
832
-		$notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) );
832
+		$notes_array = array_reverse(array_filter(explode("\n\n", $all_notes)));
833 833
 
834
-		$desired_notes = array_slice( $notes_array, $offset, $length );
834
+		$desired_notes = array_slice($notes_array, $offset, $length);
835 835
 
836 836
 		return $desired_notes;
837 837
 
@@ -848,9 +848,9 @@  discard block
 block discarded – undo
848 848
 	public function get_notes_count() {
849 849
 
850 850
 		$all_notes   = $this->get_raw_notes();
851
-		$notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) );
851
+		$notes_array = array_reverse(array_filter(explode("\n\n", $all_notes)));
852 852
 
853
-		return count( $notes_array );
853
+		return count($notes_array);
854 854
 
855 855
 	}
856 856
 
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
 	 *
864 864
 	 * @return string|float
865 865
 	 */
866
-	public function get_total_donation_amount( $args = array() ) {
866
+	public function get_total_donation_amount($args = array()) {
867 867
 
868 868
 		/**
869 869
 		 * Filter total donation amount.
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
 		 * @param integer      $donor_id       Donor ID.
875 875
 		 * @param array        $args           Pass additional data.
876 876
 		 */
877
-		return apply_filters( 'give_get_total_donation_amount', $this->purchase_value, $this->id, $args );
877
+		return apply_filters('give_get_total_donation_amount', $this->purchase_value, $this->id, $args);
878 878
 	}
879 879
 
880 880
 	/**
@@ -887,22 +887,22 @@  discard block
 block discarded – undo
887 887
 	 *
888 888
 	 * @return string|boolean The new note if added successfully, false otherwise.
889 889
 	 */
890
-	public function add_note( $note = '' ) {
890
+	public function add_note($note = '') {
891 891
 
892
-		$note = trim( $note );
893
-		if ( empty( $note ) ) {
892
+		$note = trim($note);
893
+		if (empty($note)) {
894 894
 			return false;
895 895
 		}
896 896
 
897 897
 		$notes = $this->get_raw_notes();
898 898
 
899
-		if ( empty( $notes ) ) {
899
+		if (empty($notes)) {
900 900
 			$notes = '';
901 901
 		}
902 902
 
903
-		$note_string = date_i18n( 'F j, Y H:i:s', current_time( 'timestamp' ) ) . ' - ' . $note;
904
-		$new_note    = apply_filters( 'give_customer_add_note_string', $note_string );
905
-		$notes       .= "\n\n" . $new_note;
903
+		$note_string = date_i18n('F j, Y H:i:s', current_time('timestamp')).' - '.$note;
904
+		$new_note    = apply_filters('give_customer_add_note_string', $note_string);
905
+		$notes .= "\n\n".$new_note;
906 906
 
907 907
 		/**
908 908
 		 * Fires before donor note is added.
@@ -912,11 +912,11 @@  discard block
 block discarded – undo
912 912
 		 * @param string $new_note New note to add.
913 913
 		 * @param int $donor_id Donor id.
914 914
 		 */
915
-		do_action( 'give_donor_pre_add_note', $new_note, $this->id );
915
+		do_action('give_donor_pre_add_note', $new_note, $this->id);
916 916
 
917
-		$updated = $this->update( array( 'notes' => $notes ) );
917
+		$updated = $this->update(array('notes' => $notes));
918 918
 
919
-		if ( $updated ) {
919
+		if ($updated) {
920 920
 			$this->notes = $this->get_notes();
921 921
 		}
922 922
 
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
 		 * @param string $new_note New note added.
930 930
 		 * @param int $donor_id Donor id.
931 931
 		 */
932
-		do_action( 'give_donor_post_add_note', $this->notes, $new_note, $this->id );
932
+		do_action('give_donor_post_add_note', $this->notes, $new_note, $this->id);
933 933
 
934 934
 		// Return the formatted note, so we can test, as well as update any displays
935 935
 		return $new_note;
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
 	 */
947 947
 	private function get_raw_notes() {
948 948
 
949
-		$all_notes = $this->db->get_column( 'notes', $this->id );
949
+		$all_notes = $this->db->get_column('notes', $this->id);
950 950
 
951 951
 		return $all_notes;
952 952
 
@@ -963,8 +963,8 @@  discard block
 block discarded – undo
963 963
 	 *
964 964
 	 * @return mixed            Will be an array if $single is false. Will be value of meta data field if $single is true.
965 965
 	 */
966
-	public function get_meta( $meta_key = '', $single = true ) {
967
-		return Give()->donor_meta->get_meta( $this->id, $meta_key, $single );
966
+	public function get_meta($meta_key = '', $single = true) {
967
+		return Give()->donor_meta->get_meta($this->id, $meta_key, $single);
968 968
 	}
969 969
 
970 970
 	/**
@@ -979,8 +979,8 @@  discard block
 block discarded – undo
979 979
 	 *
980 980
 	 * @return bool               False for failure. True for success.
981 981
 	 */
982
-	public function add_meta( $meta_key = '', $meta_value, $unique = false ) {
983
-		return Give()->donor_meta->add_meta( $this->id, $meta_key, $meta_value, $unique );
982
+	public function add_meta($meta_key = '', $meta_value, $unique = false) {
983
+		return Give()->donor_meta->add_meta($this->id, $meta_key, $meta_value, $unique);
984 984
 	}
985 985
 
986 986
 	/**
@@ -995,8 +995,8 @@  discard block
 block discarded – undo
995 995
 	 *
996 996
 	 * @return bool               False on failure, true if success.
997 997
 	 */
998
-	public function update_meta( $meta_key = '', $meta_value, $prev_value = '' ) {
999
-		return Give()->donor_meta->update_meta( $this->id, $meta_key, $meta_value, $prev_value );
998
+	public function update_meta($meta_key = '', $meta_value, $prev_value = '') {
999
+		return Give()->donor_meta->update_meta($this->id, $meta_key, $meta_value, $prev_value);
1000 1000
 	}
1001 1001
 
1002 1002
 	/**
@@ -1010,8 +1010,8 @@  discard block
 block discarded – undo
1010 1010
 	 *
1011 1011
 	 * @return bool               False for failure. True for success.
1012 1012
 	 */
1013
-	public function delete_meta( $meta_key = '', $meta_value = '' ) {
1014
-		return Give()->donor_meta->delete_meta( $this->id, $meta_key, $meta_value );
1013
+	public function delete_meta($meta_key = '', $meta_value = '') {
1014
+		return Give()->donor_meta->delete_meta($this->id, $meta_key, $meta_value);
1015 1015
 	}
1016 1016
 
1017 1017
 	/**
@@ -1024,51 +1024,51 @@  discard block
 block discarded – undo
1024 1024
 	 *
1025 1025
 	 * @return array       The sanitized data, based off column defaults.
1026 1026
 	 */
1027
-	private function sanitize_columns( $data ) {
1027
+	private function sanitize_columns($data) {
1028 1028
 
1029 1029
 		$columns        = $this->db->get_columns();
1030 1030
 		$default_values = $this->db->get_column_defaults();
1031 1031
 
1032
-		foreach ( $columns as $key => $type ) {
1032
+		foreach ($columns as $key => $type) {
1033 1033
 
1034 1034
 			// Only sanitize data that we were provided
1035
-			if ( ! array_key_exists( $key, $data ) ) {
1035
+			if ( ! array_key_exists($key, $data)) {
1036 1036
 				continue;
1037 1037
 			}
1038 1038
 
1039
-			switch ( $type ) {
1039
+			switch ($type) {
1040 1040
 
1041 1041
 				case '%s':
1042
-					if ( 'email' == $key ) {
1043
-						$data[ $key ] = sanitize_email( $data[ $key ] );
1044
-					} elseif ( 'notes' == $key ) {
1045
-						$data[ $key ] = strip_tags( $data[ $key ] );
1042
+					if ('email' == $key) {
1043
+						$data[$key] = sanitize_email($data[$key]);
1044
+					} elseif ('notes' == $key) {
1045
+						$data[$key] = strip_tags($data[$key]);
1046 1046
 					} else {
1047
-						$data[ $key ] = sanitize_text_field( $data[ $key ] );
1047
+						$data[$key] = sanitize_text_field($data[$key]);
1048 1048
 					}
1049 1049
 					break;
1050 1050
 
1051 1051
 				case '%d':
1052
-					if ( ! is_numeric( $data[ $key ] ) || (int) $data[ $key ] !== absint( $data[ $key ] ) ) {
1053
-						$data[ $key ] = $default_values[ $key ];
1052
+					if ( ! is_numeric($data[$key]) || (int) $data[$key] !== absint($data[$key])) {
1053
+						$data[$key] = $default_values[$key];
1054 1054
 					} else {
1055
-						$data[ $key ] = absint( $data[ $key ] );
1055
+						$data[$key] = absint($data[$key]);
1056 1056
 					}
1057 1057
 					break;
1058 1058
 
1059 1059
 				case '%f':
1060 1060
 					// Convert what was given to a float
1061
-					$value = floatval( $data[ $key ] );
1061
+					$value = floatval($data[$key]);
1062 1062
 
1063
-					if ( ! is_float( $value ) ) {
1064
-						$data[ $key ] = $default_values[ $key ];
1063
+					if ( ! is_float($value)) {
1064
+						$data[$key] = $default_values[$key];
1065 1065
 					} else {
1066
-						$data[ $key ] = $value;
1066
+						$data[$key] = $value;
1067 1067
 					}
1068 1068
 					break;
1069 1069
 
1070 1070
 				default:
1071
-					$data[ $key ] = sanitize_text_field( $data[ $key ] );
1071
+					$data[$key] = sanitize_text_field($data[$key]);
1072 1072
 					break;
1073 1073
 
1074 1074
 			}
@@ -1088,33 +1088,33 @@  discard block
 block discarded – undo
1088 1088
 	 *
1089 1089
 	 * @return bool            If the email was added successfully
1090 1090
 	 */
1091
-	public function add_email( $email = '', $primary = false ) {
1092
-		if ( ! is_email( $email ) ) {
1091
+	public function add_email($email = '', $primary = false) {
1092
+		if ( ! is_email($email)) {
1093 1093
 			return false;
1094 1094
 		}
1095
-		$existing = new Give_Donor( $email );
1095
+		$existing = new Give_Donor($email);
1096 1096
 
1097
-		if ( $existing->id > 0 ) {
1097
+		if ($existing->id > 0) {
1098 1098
 			// Email address already belongs to another donor
1099 1099
 			return false;
1100 1100
 		}
1101 1101
 
1102
-		if ( email_exists( $email ) ) {
1103
-			$user = get_user_by( 'email', $email );
1104
-			if ( $user->ID != $this->user_id ) {
1102
+		if (email_exists($email)) {
1103
+			$user = get_user_by('email', $email);
1104
+			if ($user->ID != $this->user_id) {
1105 1105
 				return false;
1106 1106
 			}
1107 1107
 		}
1108 1108
 
1109
-		do_action( 'give_donor_pre_add_email', $email, $this->id, $this );
1109
+		do_action('give_donor_pre_add_email', $email, $this->id, $this);
1110 1110
 
1111 1111
 		// Add is used to ensure duplicate emails are not added
1112
-		$ret = (bool) $this->add_meta( 'additional_email', $email );
1112
+		$ret = (bool) $this->add_meta('additional_email', $email);
1113 1113
 
1114
-		do_action( 'give_donor_post_add_email', $email, $this->id, $this );
1114
+		do_action('give_donor_post_add_email', $email, $this->id, $this);
1115 1115
 
1116
-		if ( $ret && true === $primary ) {
1117
-			$this->set_primary_email( $email );
1116
+		if ($ret && true === $primary) {
1117
+			$this->set_primary_email($email);
1118 1118
 		}
1119 1119
 
1120 1120
 		return $ret;
@@ -1130,16 +1130,16 @@  discard block
 block discarded – undo
1130 1130
 	 *
1131 1131
 	 * @return bool          If the email was removed successfully.
1132 1132
 	 */
1133
-	public function remove_email( $email = '' ) {
1134
-		if ( ! is_email( $email ) ) {
1133
+	public function remove_email($email = '') {
1134
+		if ( ! is_email($email)) {
1135 1135
 			return false;
1136 1136
 		}
1137 1137
 
1138
-		do_action( 'give_donor_pre_remove_email', $email, $this->id, $this );
1138
+		do_action('give_donor_pre_remove_email', $email, $this->id, $this);
1139 1139
 
1140
-		$ret = (bool) $this->delete_meta( 'additional_email', $email );
1140
+		$ret = (bool) $this->delete_meta('additional_email', $email);
1141 1141
 
1142
-		do_action( 'give_donor_post_remove_email', $email, $this->id, $this );
1142
+		do_action('give_donor_post_remove_email', $email, $this->id, $this);
1143 1143
 
1144 1144
 		return $ret;
1145 1145
 	}
@@ -1156,16 +1156,16 @@  discard block
 block discarded – undo
1156 1156
 	 *
1157 1157
 	 * @return bool                      If the email was set as primary successfully.
1158 1158
 	 */
1159
-	public function set_primary_email( $new_primary_email = '' ) {
1160
-		if ( ! is_email( $new_primary_email ) ) {
1159
+	public function set_primary_email($new_primary_email = '') {
1160
+		if ( ! is_email($new_primary_email)) {
1161 1161
 			return false;
1162 1162
 		}
1163 1163
 
1164
-		do_action( 'give_donor_pre_set_primary_email', $new_primary_email, $this->id, $this );
1164
+		do_action('give_donor_pre_set_primary_email', $new_primary_email, $this->id, $this);
1165 1165
 
1166
-		$existing = new Give_Donor( $new_primary_email );
1166
+		$existing = new Give_Donor($new_primary_email);
1167 1167
 
1168
-		if ( $existing->id > 0 && (int) $existing->id !== (int) $this->id ) {
1168
+		if ($existing->id > 0 && (int) $existing->id !== (int) $this->id) {
1169 1169
 			// This email belongs to another donor.
1170 1170
 			return false;
1171 1171
 		}
@@ -1173,21 +1173,21 @@  discard block
 block discarded – undo
1173 1173
 		$old_email = $this->email;
1174 1174
 
1175 1175
 		// Update donor record with new email.
1176
-		$update = $this->update( array( 'email' => $new_primary_email ) );
1176
+		$update = $this->update(array('email' => $new_primary_email));
1177 1177
 
1178 1178
 		// Remove new primary from list of additional emails.
1179
-		$remove = $this->remove_email( $new_primary_email );
1179
+		$remove = $this->remove_email($new_primary_email);
1180 1180
 
1181 1181
 		// Add old email to additional emails list.
1182
-		$add = $this->add_email( $old_email );
1182
+		$add = $this->add_email($old_email);
1183 1183
 
1184 1184
 		$ret = $update && $remove && $add;
1185 1185
 
1186
-		if ( $ret ) {
1186
+		if ($ret) {
1187 1187
 			$this->email = $new_primary_email;
1188 1188
 		}
1189 1189
 
1190
-		do_action( 'give_donor_post_set_primary_email', $new_primary_email, $this->id, $this );
1190
+		do_action('give_donor_post_set_primary_email', $new_primary_email, $this->id, $this);
1191 1191
 
1192 1192
 		return $ret;
1193 1193
 	}
@@ -1202,17 +1202,17 @@  discard block
 block discarded – undo
1202 1202
 	 *
1203 1203
 	 * @return bool
1204 1204
 	 */
1205
-	private function is_valid_address( $address ) {
1205
+	private function is_valid_address($address) {
1206 1206
 		$is_valid_address = true;
1207 1207
 		
1208 1208
 		// Address ready to process even if only one value set.
1209
-		foreach ( $address as $address_type => $value ) {
1209
+		foreach ($address as $address_type => $value) {
1210 1210
 			// @todo: Handle state field validation on basis of country.
1211
-			if( in_array( $address_type, array( 'line2', 'state' )) ) {
1211
+			if (in_array($address_type, array('line2', 'state'))) {
1212 1212
 				continue;
1213 1213
 			}
1214 1214
 
1215
-			if ( empty( $value ) ) {
1215
+			if (empty($value)) {
1216 1216
 				$is_valid_address = false;
1217 1217
 				break;
1218 1218
 			}
@@ -1239,30 +1239,27 @@  discard block
 block discarded – undo
1239 1239
 	 *
1240 1240
 	 * @return bool
1241 1241
 	 */
1242
-	public function add_address( $address_type, $address ) {
1242
+	public function add_address($address_type, $address) {
1243 1243
 		// Bailout.
1244
-		if ( empty( $address_type ) || ! $this->is_valid_address( $address ) || ! $this->id ) {
1244
+		if (empty($address_type) || ! $this->is_valid_address($address) || ! $this->id) {
1245 1245
 			return false;
1246 1246
 		}
1247 1247
 
1248 1248
 		// Check if multiple address exist or not and set params.
1249 1249
 		$multi_address_id = null;
1250
-		if( $is_multi_address = ( false !== strpos( $address_type, '[]' ) ) ) {
1251
-			$address_type  = $is_multi_address ?
1252
-				str_replace( '[]', '', $address_type ) :
1253
-				$address_type;
1254
-		} elseif ( $is_multi_address = ( false !== strpos( $address_type, '_' ) ) ){
1255
-			$multi_address_id =  $is_multi_address ?
1256
-				array_pop( explode( '_', $address_type ) ) :
1257
-				$address_type;
1258
-
1259
-			$address_type  = $is_multi_address ?
1260
-				array_shift( explode( '_', $address_type ) ) :
1261
-				$address_type;
1250
+		if ($is_multi_address = (false !== strpos($address_type, '[]'))) {
1251
+			$address_type = $is_multi_address ?
1252
+				str_replace('[]', '', $address_type) : $address_type;
1253
+		} elseif ($is_multi_address = (false !== strpos($address_type, '_'))) {
1254
+			$multi_address_id = $is_multi_address ?
1255
+				array_pop(explode('_', $address_type)) : $address_type;
1256
+
1257
+			$address_type = $is_multi_address ?
1258
+				array_shift(explode('_', $address_type)) : $address_type;
1262 1259
 		}
1263 1260
 
1264 1261
 		// Bailout: do not save duplicate orders
1265
-		if( $this->is_address_exist( $address_type, $address ) ) {
1262
+		if ($this->is_address_exist($address_type, $address)) {
1266 1263
 			return false;
1267 1264
 		}
1268 1265
 
@@ -1284,8 +1281,8 @@  discard block
 block discarded – undo
1284 1281
 		$meta_key_prefix = "_give_donor_address_{$address_type}_{address_name}";
1285 1282
 		$meta_type = Give()->donor_meta->meta_type;
1286 1283
 
1287
-		if ( $is_multi_address ) {
1288
-			if ( is_null( $multi_address_id ) ) {
1284
+		if ($is_multi_address) {
1285
+			if (is_null($multi_address_id)) {
1289 1286
 				// Get latest address key to set multi address id.
1290 1287
 				$multi_address_id = $wpdb->get_var(
1291 1288
 					$wpdb->prepare(
@@ -1302,10 +1299,10 @@  discard block
 block discarded – undo
1302 1299
 					)
1303 1300
 				);
1304 1301
 
1305
-				if( ! empty( $multi_address_id ) ) {
1306
-					$multi_address_id = absint( substr( strrchr( $multi_address_id, '_' ), 1 ) );
1302
+				if ( ! empty($multi_address_id)) {
1303
+					$multi_address_id = absint(substr(strrchr($multi_address_id, '_'), 1));
1307 1304
 					$multi_address_id++;
1308
-				} else{
1305
+				} else {
1309 1306
 					$multi_address_id = 0;
1310 1307
 				}
1311 1308
 			}
@@ -1314,9 +1311,9 @@  discard block
 block discarded – undo
1314 1311
 		}
1315 1312
 
1316 1313
 		// Save donor address.
1317
-		foreach ( $address as $type => $value ) {
1318
-			$meta_key = str_replace( '{address_name}', $type, $meta_key_prefix );
1319
-			Give()->donor_meta->update_meta( $this->id, $meta_key, $value );
1314
+		foreach ($address as $type => $value) {
1315
+			$meta_key = str_replace('{address_name}', $type, $meta_key_prefix);
1316
+			Give()->donor_meta->update_meta($this->id, $meta_key, $value);
1320 1317
 		}
1321 1318
 
1322 1319
 		$this->setup_address();
@@ -1335,23 +1332,21 @@  discard block
 block discarded – undo
1335 1332
 	 *
1336 1333
 	 * @return bool
1337 1334
 	 */
1338
-	public function remove_address( $address_id ) {
1335
+	public function remove_address($address_id) {
1339 1336
 		global $wpdb;
1340 1337
 
1341 1338
 		// Get address type.
1342
-		$is_multi_address = false !== strpos( $address_id, '_' ) ? true : false;
1339
+		$is_multi_address = false !== strpos($address_id, '_') ? true : false;
1343 1340
 
1344
-		$address_type = false !== strpos( $address_id, '_' ) ?
1345
-			array_shift( explode( '_', $address_id ) ) :
1346
-			$address_id;
1341
+		$address_type = false !== strpos($address_id, '_') ?
1342
+			array_shift(explode('_', $address_id)) : $address_id;
1347 1343
 
1348
-		$address_count = false !== strpos( $address_id, '_' ) ?
1349
-			array_pop( explode( '_', $address_id ) ) :
1350
-			null;
1344
+		$address_count = false !== strpos($address_id, '_') ?
1345
+			array_pop(explode('_', $address_id)) : null;
1351 1346
 
1352 1347
 		// Set meta key prefix.
1353 1348
 		$meta_key_prefix = "_give_donor_address_{$address_type}_%";
1354
-		if ( $is_multi_address && is_numeric( $address_count ) ) {
1349
+		if ($is_multi_address && is_numeric($address_count)) {
1355 1350
 			$meta_key_prefix .= "_{$address_count}";
1356 1351
 		}
1357 1352
 
@@ -1388,23 +1383,21 @@  discard block
 block discarded – undo
1388 1383
 	 *
1389 1384
 	 * @return bool
1390 1385
 	 */
1391
-	public function update_address( $address_id, $address ) {
1386
+	public function update_address($address_id, $address) {
1392 1387
 		global $wpdb;
1393 1388
 
1394 1389
 		// Get address type.
1395
-		$is_multi_address = false !== strpos( $address_id, '_' ) ? true : false;
1390
+		$is_multi_address = false !== strpos($address_id, '_') ? true : false;
1396 1391
 
1397
-		$address_type = false !== strpos( $address_id, '_' ) ?
1398
-			array_shift( explode( '_', $address_id ) ) :
1399
-			$address_id;
1392
+		$address_type = false !== strpos($address_id, '_') ?
1393
+			array_shift(explode('_', $address_id)) : $address_id;
1400 1394
 
1401
-		$address_count = false !== strpos( $address_id, '_' ) ?
1402
-			array_pop( explode( '_', $address_id ) ) :
1403
-			null;
1395
+		$address_count = false !== strpos($address_id, '_') ?
1396
+			array_pop(explode('_', $address_id)) : null;
1404 1397
 
1405 1398
 		// Set meta key prefix.
1406 1399
 		$meta_key_prefix = "_give_donor_address_{$address_type}_%";
1407
-		if ( $is_multi_address && is_numeric( $address_count ) ) {
1400
+		if ($is_multi_address && is_numeric($address_count)) {
1408 1401
 			$meta_key_prefix .= "_{$address_count}";
1409 1402
 		}
1410 1403
 
@@ -1425,12 +1418,12 @@  discard block
 block discarded – undo
1425 1418
 		);
1426 1419
 		
1427 1420
 		// Return result.
1428
-		if( ! count( $row_affected ) ) {
1421
+		if ( ! count($row_affected)) {
1429 1422
 			return false;
1430 1423
 		}
1431 1424
 
1432 1425
 		// Update address.
1433
-		if( ! $this->add_address( $address_id, $address ) ) {
1426
+		if ( ! $this->add_address($address_id, $address)) {
1434 1427
 			return false;
1435 1428
 		}
1436 1429
 
@@ -1449,39 +1442,39 @@  discard block
 block discarded – undo
1449 1442
 	 *
1450 1443
 	 * @return bool|null
1451 1444
 	 */
1452
-	public function is_address_exist( $current_address_type, $current_address ) {
1445
+	public function is_address_exist($current_address_type, $current_address) {
1453 1446
 		$status = false;
1454 1447
 
1455 1448
 		// Bailout.
1456
-		if( empty( $current_address_type ) || empty( $current_address ) ) {
1449
+		if (empty($current_address_type) || empty($current_address)) {
1457 1450
 			return null;
1458 1451
 		}
1459 1452
 
1460 1453
 		// Bailout.
1461
-		if( empty( $this->address ) || empty( $this->address[ $current_address_type ] ) ) {
1454
+		if (empty($this->address) || empty($this->address[$current_address_type])) {
1462 1455
 			return $status;
1463 1456
 		}
1464 1457
 
1465 1458
 		// Get address.
1466
-		$address = $this->address[ $current_address_type ];
1459
+		$address = $this->address[$current_address_type];
1467 1460
 
1468
-		switch ( true ){
1461
+		switch (true) {
1469 1462
 
1470 1463
 			// Single address.
1471
-			case is_string( end( $address ) ) :
1472
-				$status = $this->is_address_match( $current_address, $address );
1464
+			case is_string(end($address)) :
1465
+				$status = $this->is_address_match($current_address, $address);
1473 1466
 				break;
1474 1467
 
1475 1468
 			// Multi address.
1476
-			case is_array( end( $address ) ):
1469
+			case is_array(end($address)):
1477 1470
 				// Compare address.
1478
-				foreach ( $address as $saved_address ) {
1479
-					if( empty( $saved_address ) ) {
1471
+				foreach ($address as $saved_address) {
1472
+					if (empty($saved_address)) {
1480 1473
 						continue;
1481 1474
 					}
1482 1475
 
1483 1476
 					// Exit loop immediately if address exist.
1484
-					if( $status = $this->is_address_match( $current_address, $saved_address ) ) {
1477
+					if ($status = $this->is_address_match($current_address, $saved_address)) {
1485 1478
 						break;
1486 1479
 					}
1487 1480
 				}
@@ -1502,10 +1495,10 @@  discard block
 block discarded – undo
1502 1495
 	 *
1503 1496
 	 * @return bool
1504 1497
 	 */
1505
-	private function is_address_match( $address_1, $address_2 ) {
1506
-		$result = array_diff( $address_1, $address_2 );
1498
+	private function is_address_match($address_1, $address_2) {
1499
+		$result = array_diff($address_1, $address_2);
1507 1500
 
1508
-		return empty( $result );
1501
+		return empty($result);
1509 1502
 	}
1510 1503
 
1511 1504
 	/**
@@ -1515,22 +1508,22 @@  discard block
 block discarded – undo
1515 1508
 	 * @since   2.0
1516 1509
 	 * @return  object
1517 1510
 	 */
1518
-	public function split_donor_name( $id ) {
1519
-		$first_name = $last_name  = '';
1520
-		$donor      = new Give_Donor( $id );
1511
+	public function split_donor_name($id) {
1512
+		$first_name = $last_name = '';
1513
+		$donor      = new Give_Donor($id);
1521 1514
 
1522
-		$split_donor_name = explode( ' ', $donor->name, 2 );
1515
+		$split_donor_name = explode(' ', $donor->name, 2);
1523 1516
 
1524 1517
 		// Check for existence of first name after split of donor name.
1525
-		if( is_array( $split_donor_name ) && ! empty( $split_donor_name[0] ) ) {
1518
+		if (is_array($split_donor_name) && ! empty($split_donor_name[0])) {
1526 1519
 			$first_name = $split_donor_name[0];
1527 1520
 		}
1528 1521
 
1529 1522
 		// Check for existence of last name after split of donor name.
1530
-		if( is_array( $split_donor_name ) && ! empty( $split_donor_name[1] ) ) {
1523
+		if (is_array($split_donor_name) && ! empty($split_donor_name[1])) {
1531 1524
 			$last_name = $split_donor_name[1];
1532 1525
 		}
1533
-		return (object) array( 'first_name' => $first_name, 'last_name' => $last_name );
1526
+		return (object) array('first_name' => $first_name, 'last_name' => $last_name);
1534 1527
 	}
1535 1528
 
1536 1529
 	/**
@@ -1540,9 +1533,9 @@  discard block
 block discarded – undo
1540 1533
 	 * @return  string
1541 1534
 	 */
1542 1535
 	public function get_first_name() {
1543
-		$first_name = $this->get_meta( '_give_donor_first_name');
1544
-		if( ! $first_name ) {
1545
-			$first_name = $this->split_donor_name( $this->id )->first_name;
1536
+		$first_name = $this->get_meta('_give_donor_first_name');
1537
+		if ( ! $first_name) {
1538
+			$first_name = $this->split_donor_name($this->id)->first_name;
1546 1539
 		}
1547 1540
 
1548 1541
 		return $first_name;
@@ -1555,14 +1548,14 @@  discard block
 block discarded – undo
1555 1548
 	 * @return  string
1556 1549
 	 */
1557 1550
 	public function get_last_name() {
1558
-		$first_name = $this->get_meta( '_give_donor_first_name');
1559
-		$last_name = $this->get_meta( '_give_donor_last_name');
1551
+		$first_name = $this->get_meta('_give_donor_first_name');
1552
+		$last_name = $this->get_meta('_give_donor_last_name');
1560 1553
 
1561 1554
 		// This condition will prevent unnecessary splitting of donor name to fetch last name.
1562
-		if( ! $first_name && ! $last_name ) {
1563
-			$last_name = $this->split_donor_name( $this->id )->last_name;
1555
+		if ( ! $first_name && ! $last_name) {
1556
+			$last_name = $this->split_donor_name($this->id)->last_name;
1564 1557
 		}
1565 1558
 
1566
-		return ( $last_name ) ? $last_name : '';
1559
+		return ($last_name) ? $last_name : '';
1567 1560
 	}
1568 1561
 }
Please login to merge, or discard this patch.