Test Failed
Push — feature/post-pay ( e3663d...906e88 )
by Remco
04:22
created

OrderItems::add_item()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Order items.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\OmniKassa2
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;
12
13
/**
14
 * Order items.
15
 *
16
 * @author  Reüel van der Steege
17
 * @version 2.0.3
18
 * @since   2.0.3
19
 */
20
class OrderItems {
21
	/**
22
	 * Order items.
23
	 *
24
	 * @var array
25
	 */
26
	private $order_items;
27
28
	/**
29
	 * Construct order results message.
30
	 *
31
	 * @param array $items Order items.
32
	 */
33
	public function __construct( $items = null ) {
34
		if ( is_array( $items ) ) {
35
			foreach ( $items as $item ) {
36
				$this->add_item( $item );
37
			}
38
		}
39
	}
40
41
	/**
42
	 * Create and add new order item.
43
	 *
44
	 * @return OrderItem
45
	 */
46
	public function new_item( $name, $quantity, Money $amount, $category ) {
47
		$item = new OrderItem( $name, $quantity, $amount, $category );
48
49
		$this->add_item( $item ):
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ':' on line 49 at column 26
Loading history...
50
51
		return $item;
52
	}
53
54
	/**
55
	 * Add order item.
56
	 *
57
	 * @param OrderItem $item Order item.
58
	 */
59
	public function add_item( OrderItem $item ) {
60
		$this->order_items[] = $item;
61
	}
62
63
	/**
64
	 * Get order items.
65
	 *
66
	 * @return array
67
	 */
68
	public function get_order_items() {
69
		return $this->order_items;
70
	}
71
72
	/**
73
	 * Get JSON.
74
	 *
75
	 * @return array|null
76
	 */
77
	public function get_json() {
78
		$data = array_map(
79
			function( $item ) {
80
				return $item->get_json();
81
			},
82
			$this->get_order_items()
83
		);
84
85
		return $data;
86
	}
87
88
	/**
89
	 * Get signature fields.
90
	 *
91
	 * @param array $fields Fields.
92
	 * @return array
93
	 */
94
	public function get_signature_fields( $fields = array() ) {
95
		foreach ( $this->get_order_items() as $item ) {
96
			$fields = $item->get_signature_fields( $fields );
97
		}
98
99
		return $fields;
100
	}
101
}
102