Passed
Push — feature/post-pay ( 906e88...faf3dd )
by Remco
04:39
created

OrderItem   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 245
Duplicated Lines 0 %

Test Coverage

Coverage 50.77%

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 245
ccs 33
cts 65
cp 0.5077
rs 10
c 0
b 0
f 0
wmc 22

15 Methods

Rating   Name   Duplication   Size   Complexity  
A get_id() 0 2 1
A get_description() 0 2 1
A set_id() 0 2 1
A get_category() 0 2 1
A get_json() 0 27 5
A get_name() 0 2 1
A set_vat_category() 0 2 1
A get_signature_fields() 0 25 4
A set_description() 0 2 1
A get_tax() 0 2 1
A get_vat_category() 0 2 1
A get_amount() 0 2 1
A set_tax() 0 2 1
A get_quantity() 0 2 1
A __construct() 0 5 1
1
<?php
2
/**
3
 * Order item.
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 item.
15
 *
16
 * @author  Reüel van der Steege
17
 * @version 2.0.3
18
 * @since   2.0.3
19
 */
20
class OrderItem {
21
	/**
22
	 * Item id.
23
	 *
24
	 * @var string
25
	 */
26
	private $id;
27
28
	/**
29
	 * Item name (required).
30
	 *
31
	 * @var string
32
	 */
33
	private $name;
34
35
	/**
36
	 * Description.
37
	 *
38
	 * @var string
39
	 */
40
	private $description;
41
42
	/**
43
	 * Quantity (required).
44
	 *
45
	 * @var int
46
	 */
47
	private $quantity;
48
49
	/**
50
	 * Amount (required).
51
	 *
52
	 * @var Money
53
	 */
54
	private $amount;
55
56
	/**
57
	 * Tax.
58
	 *
59
	 * @var Money
60
	 */
61
	private $tax;
62
63
	/**
64
	 * Category; physical or digital (required).
65
	 *
66
	 * @var string
67
	 */
68
	private $category;
69
70
	/**
71
	 * VAT category.
72
	 *
73
	 * @var int
74
	 */
75
	private $vat_category;
76
77
	/**
78
	 * Construct order result.
79
	 *
80
	 * @param string $name     Name.
81
	 * @param int    $quantity Quantity.
82
	 * @param Money  $amount   Amount.
83
	 * @param string $category Category.
84
	 */
85 1
	public function __construct( $name, $quantity, Money $amount, $category ) {
86 1
		$this->name     = $name;
87 1
		$this->quantity = $quantity;
88 1
		$this->amount   = $amount;
89 1
		$this->category = $category;
90 1
	}
91
92
	/**
93
	 * Get item ID.
94
	 *
95
	 * @return string
96
	 */
97
	public function get_id() {
98
		return $this->id;
99
	}
100
101
	/**
102
	 * Set item ID.
103
	 *
104
	 * @param string|null $id ID.
105
	 */
106 1
	public function set_id( $id = null ) {
107 1
		$this->id = $id;
108 1
	}
109
110
	/**
111
	 * Get item name.
112
	 *
113
	 * @return string
114
	 */
115
	public function get_name() {
116
		return $this->name;
117
	}
118
119
	/**
120
	 * Get item description.
121
	 *
122
	 * @return string
123
	 */
124
	public function get_description() {
125
		return $this->description;
126
	}
127
128
	/**
129
	 * Set item description.
130
	 *
131
	 * @param string $description Description.
132
	 */
133 1
	public function set_description( $description ) {
134 1
		$this->description = $description;
135 1
	}
136
137
	/**
138
	 * Get quantity.
139
	 *
140
	 * @return int
141
	 */
142
	public function get_quantity() {
143
		return $this->quantity;
144
	}
145
146
	/**
147
	 * Get amount.
148
	 *
149
	 * @return Money
150
	 */
151
	public function get_amount() {
152
		return $this->amount;
153
	}
154
155
	/**
156
	 * Get tax.
157
	 *
158
	 * @return Money
159
	 */
160
	public function get_tax() {
161
		return $this->tax;
162
	}
163
164
	/**
165
	 * Set tax.
166
	 *
167
	 * @param Money|null $tax Tax.
168
	 */
169 1
	public function set_tax( Money $tax = null ) {
170 1
		$this->tax = $tax;
171 1
	}
172
173
	/**
174
	 * Get category.
175
	 *
176
	 * @return string
177
	 */
178
	public function get_category() {
179
		return $this->category;
180
	}
181
182
	/**
183
	 * Get VAT category.
184
	 *
185
	 * @return int
186
	 */
187
	public function get_vat_category() {
188
		return $this->vat_category;
189
	}
190
191
	/**
192
	 * Set VAT category.
193
	 *
194
	 * @param int $vat_category VAT category.
195
	 */
196 1
	public function set_vat_category( $vat_category ) {
197 1
		$this->vat_category = $vat_category;
198 1
	}
199
200
	/**
201
	 * Get JSON.
202
	 *
203
	 * @return object
204
	 */
205
	public function get_json() {
206
		$object = (object) array();
207
208
		if ( null !== $this->id ) {
209
			$object->id = $this->id;
210
		}
211
212
		$object->name = $this->name;
213
214
		if ( null !== $this->description ) {
215
			$object->description = $this->description;
216
		}
217
218
		$object->quantity = $this->quantity;
219
		$object->amount   = $this->amount->get_json();
220
221
		if ( null !== $this->tax ) {
222
			$object->tax = $this->tax->get_json();
223
		}
224
225
		$object->category = $this->category;
226
227
		if ( null !== $this->vat_category ) {
228
			$object->vatCategory = $this->vat_category;
229
		}
230
231
		return $object;
232
	}
233
234
	/**
235
	 * Get signature data.
236
	 *
237
	 * @param array $data Data.
238
	 * @return array
239
	 */
240 1
	public function get_signature_fields( $data = array() ) {
241 1
		if ( null !== $this->id ) {
242 1
			$data[] = $this->id;
243
		}
244
245 1
		$data[] = $this->name;
246 1
		$data[] = $this->description;
247 1
		$data[] = $this->quantity;
248 1
		$data[] = $this->amount->get_currency();
249 1
		$data[] = $this->amount->get_amount();
250
251 1
		if ( null === $this->tax ) {
252
			$data[] = null;
253
		} else {
254 1
			$data[] = $this->tax->get_currency();
255 1
			$data[] = $this->tax->get_amount();
256
		}
257
258 1
		$data[] = $this->category;
259
260 1
		if ( null !== $this->vat_category ) {
261 1
			$data[] = $this->vat_category;
262
		}
263
264 1
		return $data;
265
	}
266
}
267