Passed
Push — master ( e8e8db...e29aba )
by Brian
04:14
created
includes/payments/class-getpaid-payment-form-submission-items.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -12,80 +12,80 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20
+
21
+    /**
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30
+
31
+        // Prepare the selected items.
32
+        $selected_items = array();
33
+        if ( ! empty( $data['getpaid-items'] ) ) {
34
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
35
+        }
36
+
37
+        // For default forms, ensure that an item has been set.
38
+        if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) {
39
+            $form_items = wpinv_clean( $data['getpaid-form-items'] );
40
+            $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) );
41
+        }
42
+
43
+        // Process each individual item.
44
+        foreach ( $payment_form->get_items() as $item ) {
45
+            $this->process_item( $item, $selected_items, $submission );
46
+        }
47
+
48
+    }
20 49
 
21 50
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
30
-
31
-		// Prepare the selected items.
32
-		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
-		}
36
-
37
-		// For default forms, ensure that an item has been set.
38
-		if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) {
39
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
40
-			$payment_form->set_items( getpaid_convert_items_to_array( $form_items ) );
41
-		}
42
-
43
-		// Process each individual item.
44
-		foreach ( $payment_form->get_items() as $item ) {
45
-			$this->process_item( $item, $selected_items, $submission );
46
-		}
47
-
48
-	}
49
-
50
-	/**
51
-	 * Process a single item.
52
-	 *
53
-	 * @param GetPaid_Form_Item $item
54
-	 * @param array $selected_items
55
-	 * @param GetPaid_Payment_Form_Submission $submission
56
-	 */
57
-	public function process_item( $item, $selected_items, $submission ) {
58
-
59
-		// Abort if this is an optional item and it has not been selected.
60
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
61
-			return;
62
-		}
63
-
64
-		// (maybe) let customers change the quantities and prices.
65
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
66
-
67
-			// Maybe change the quantities.
68
-			if ( $item->allows_quantities() ) {
69
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
70
-			}
71
-
72
-			// Maybe change the price.
73
-			if ( $item->user_can_set_their_price() ) {
74
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
75
-
76
-				if ( $item->get_minimum_price() > $price ) {
77
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) );
78
-				}
79
-
80
-				$item->set_price( $price );
81
-
82
-			}
83
-
84
-		}
85
-
86
-		// Save the item.
87
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
88
-
89
-	}
51
+     * Process a single item.
52
+     *
53
+     * @param GetPaid_Form_Item $item
54
+     * @param array $selected_items
55
+     * @param GetPaid_Payment_Form_Submission $submission
56
+     */
57
+    public function process_item( $item, $selected_items, $submission ) {
58
+
59
+        // Abort if this is an optional item and it has not been selected.
60
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
61
+            return;
62
+        }
63
+
64
+        // (maybe) let customers change the quantities and prices.
65
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
66
+
67
+            // Maybe change the quantities.
68
+            if ( $item->allows_quantities() ) {
69
+                $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
70
+            }
71
+
72
+            // Maybe change the price.
73
+            if ( $item->user_can_set_their_price() ) {
74
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
75
+
76
+                if ( $item->get_minimum_price() > $price ) {
77
+                    throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) );
78
+                }
79
+
80
+                $item->set_price( $price );
81
+
82
+            }
83
+
84
+        }
85
+
86
+        // Save the item.
87
+        $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
88
+
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission itemss class
@@ -23,26 +23,26 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$data         = $submission->get_data();
29 29
 		$payment_form = $submission->get_payment_form();
30 30
 
31 31
 		// Prepare the selected items.
32 32
 		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
33
+		if (!empty($data['getpaid-items'])) {
34
+			$selected_items = wpinv_clean($data['getpaid-items']);
35 35
 		}
36 36
 
37 37
 		// For default forms, ensure that an item has been set.
38
-		if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) {
39
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
40
-			$payment_form->set_items( getpaid_convert_items_to_array( $form_items ) );
38
+		if ($payment_form->is_default() && (!$submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via()) && isset($data['getpaid-form-items'])) {
39
+			$form_items = wpinv_clean($data['getpaid-form-items']);
40
+			$payment_form->set_items(getpaid_convert_items_to_array($form_items));
41 41
 		}
42 42
 
43 43
 		// Process each individual item.
44
-		foreach ( $payment_form->get_items() as $item ) {
45
-			$this->process_item( $item, $selected_items, $submission );
44
+		foreach ($payment_form->get_items() as $item) {
45
+			$this->process_item($item, $selected_items, $submission);
46 46
 		}
47 47
 
48 48
 	}
@@ -54,37 +54,37 @@  discard block
 block discarded – undo
54 54
 	 * @param array $selected_items
55 55
 	 * @param GetPaid_Payment_Form_Submission $submission
56 56
 	 */
57
-	public function process_item( $item, $selected_items, $submission ) {
57
+	public function process_item($item, $selected_items, $submission) {
58 58
 
59 59
 		// Abort if this is an optional item and it has not been selected.
60
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
60
+		if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
61 61
 			return;
62 62
 		}
63 63
 
64 64
 		// (maybe) let customers change the quantities and prices.
65
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
65
+		if (isset($selected_items[$item->get_id()])) {
66 66
 
67 67
 			// Maybe change the quantities.
68
-			if ( $item->allows_quantities() ) {
69
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
68
+			if ($item->allows_quantities()) {
69
+				$item->set_quantity((float) $selected_items[$item->get_id()]['quantity']);
70 70
 			}
71 71
 
72 72
 			// Maybe change the price.
73
-			if ( $item->user_can_set_their_price() ) {
74
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
73
+			if ($item->user_can_set_their_price()) {
74
+				$price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
75 75
 
76
-				if ( $item->get_minimum_price() > $price ) {
77
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) );
76
+				if ($item->get_minimum_price() > $price) {
77
+					throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), wpinv_sanitize_amount($item->get_minimum_price())));
78 78
 				}
79 79
 
80
-				$item->set_price( $price );
80
+				$item->set_price($price);
81 81
 
82 82
 			}
83 83
 
84 84
 		}
85 85
 
86 86
 		// Save the item.
87
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
87
+		$this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission);
88 88
 
89 89
 	}
90 90
 
Please login to merge, or discard this patch.