Passed
Push — develop ( 6cb854...ee4d39 )
by Remco
03:23
created

LineItem::set_id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Line item.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Adyen
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
12
13
use InvalidArgumentException;
14
15
/**
16
 * Line item.
17
 *
18
 * @author  Reüel van der Steege
19
 * @version 1.0.0
20
 * @since   1.0.0
21
 */
22
class LineItem {
23
	/**
24
	 * Amount excluding tax.
25
	 *
26
	 * @var int|null
27
	 */
28
	private $amount_excluding_tax;
29
30
	/**
31
	 * Amount including tax.
32
	 *
33
	 * @var int|null
34
	 */
35
	private $amount_including_tax;
36
37
	/**
38
	 * Description.
39
	 *
40
	 * @var string|null
41
	 */
42
	private $description;
43
44
	/**
45
	 * Item id.
46
	 *
47
	 * @var string|null
48
	 */
49
	private $id;
50
51
	/**
52
	 * Quantity.
53
	 *
54
	 * @var int|null
55
	 */
56
	private $quantity;
57
58
	/**
59
	 * Tax amount.
60
	 *
61
	 * @var int|null
62
	 */
63
	private $tax_amount;
64
65
	/**
66
	 * Tax category: High, Low, None, Zero.
67
	 *
68
	 * @var string|null
69
	 */
70
	private $tax_category;
71
72
	/**
73
	 * Tax percentage, in minor units.
74
	 *
75
	 * @var int|null
76
	 */
77
	private $tax_percentage;
78
79
	/**
80
	 * Construct line item.
81
	 *
82
	 * @param string $description          Name.
83
	 * @param int    $quantity             Quantity.
84
	 * @param int    $amount_including_tax Amount (including tax).
85
	 *
86
	 * @throws InvalidArgumentException Throws invalid argument exception when arguments are invalid.
87
	 */
88 4
	public function __construct( $description, $quantity, $amount_including_tax ) {
89 4
		$this->set_description( $description );
90 4
		$this->set_quantity( $quantity );
91 4
		$this->set_amount_including_tax( $amount_including_tax );
92 4
	}
93
94
	/**
95
	 * Get amount excluding tax.
96
	 *
97
	 * @return int|null
98
	 */
99 1
	public function get_amount_excluding_tax() {
100 1
		return $this->amount_excluding_tax;
101
	}
102
103
	/**
104
	 * Set amount excluding tax.
105
	 *
106
	 * @param int|null $amount_excluding_tax Amount excluding tax.
107
	 * @return void
108
	 */
109 2
	public function set_amount_excluding_tax( $amount_excluding_tax = null ) {
110 2
		$this->amount_excluding_tax = $amount_excluding_tax;
111 2
	}
112
113
	/**
114
	 * Get amount excluding tax.
115
	 *
116
	 * @return int|null
117
	 */
118 1
	public function get_amount_including_tax() {
119 1
		return $this->amount_including_tax;
120
	}
121
122
	/**
123
	 * Set amount including tax.
124
	 *
125
	 * @param int|null $amount_including_tax Amount excluding tax.
126
	 * @return void
127
	 */
128 4
	public function set_amount_including_tax( $amount_including_tax = null ) {
129 4
		$this->amount_including_tax = $amount_including_tax;
130 4
	}
131
132
	/**
133
	 * Get item description.
134
	 *
135
	 * @return string|null
136
	 */
137 1
	public function get_description() {
138 1
		return $this->description;
139
	}
140
141
	/**
142
	 * Set item description.
143
	 *
144
	 * @param string|null $description Description.
145
	 * @return void
146
	 * @throws InvalidArgumentException Throws invalid argument exception when value does not apply to format `AN..max 100`.
147
	 */
148 4
	public function set_description( $description = null ) {
149 4
		$this->description = $description;
150 4
	}
151
152
	/**
153
	 * Get item ID.
154
	 *
155
	 * @return string|null
156
	 */
157 1
	public function get_id() {
158 1
		return $this->id;
159
	}
160
161
	/**
162
	 * Set item ID.
163
	 *
164
	 * @param string|null $id ID.
165
	 * @return void
166
	 */
167 2
	public function set_id( $id = null ) {
168 2
		$this->id = $id;
169 2
	}
170
171
	/**
172
	 * Get quantity.
173
	 *
174
	 * @return int|null
175
	 */
176 1
	public function get_quantity() {
177 1
		return $this->quantity;
178
	}
179
180
	/**
181
	 * Get quantity.
182
	 *
183
	 * @param int|null $quantity Quantity.
184
	 * @return void
185
	 */
186 4
	public function set_quantity( $quantity = null ) {
187 4
		$this->quantity = $quantity;
188 4
	}
189
190
	/**
191
	 * Get tax amount.
192
	 *
193
	 * @return int|null
194
	 */
195 1
	public function get_tax_amount() {
196 1
		return $this->tax_amount;
197
	}
198
199
	/**
200
	 * Set tax amount.
201
	 *
202
	 * @param int|null $tax_amount Tax amount.
203
	 * @return void
204
	 */
205 2
	public function set_tax_amount( $tax_amount = null ) {
206 2
		$this->tax_amount = $tax_amount;
207 2
	}
208
209
	/**
210
	 * Get tax category.
211
	 *
212
	 * @return string|null
213
	 */
214 1
	public function get_tax_category() {
215 1
		return $this->tax_category;
216
	}
217
218
	/**
219
	 * Set tax category.
220
	 *
221
	 * @param string|null $tax_category Tax category.
222
	 * @return void
223
	 */
224 2
	public function set_tax_category( $tax_category ) {
225 2
		$this->tax_category = $tax_category;
226 2
	}
227
228
	/**
229
	 * Get tax percentage.
230
	 *
231
	 * @return int|null
232
	 */
233 1
	public function get_tax_percentage() {
234 1
		return $this->tax_percentage;
235
	}
236
237
	/**
238
	 * Set tax percentage.
239
	 *
240
	 * @param int|null $tax_percentage Tax percentage.
241
	 * @return void
242
	 */
243 2
	public function set_tax_percentage( $tax_percentage ) {
244 2
		$this->tax_percentage = $tax_percentage;
245 2
	}
246
247
	/**
248
	 * Get JSON.
249
	 *
250
	 * @return object
251
	 */
252 2
	public function get_json() {
253 2
		$object = (object) array();
254
255 2
		if ( null !== $this->amount_excluding_tax ) {
256 1
			$object->amountExcludingTax = $this->amount_excluding_tax;
257
		}
258
259 2
		if ( null !== $this->amount_including_tax ) {
260 2
			$object->amountIncludingTax = $this->amount_including_tax;
261
		}
262
263 2
		if ( null !== $this->description ) {
264 2
			$object->description = $this->description;
265
		}
266
267 2
		if ( null !== $this->id ) {
268 1
			$object->id = $this->id;
269
		}
270
271 2
		if ( null !== $this->quantity ) {
272 2
			$object->quantity = $this->quantity;
273
		}
274
275 2
		if ( null !== $this->tax_amount ) {
276 1
			$object->taxAmount = $this->tax_amount;
277
		}
278
279 2
		if ( null !== $this->tax_category ) {
280 1
			$object->taxCategory = $this->tax_category;
281
		}
282
283 2
		if ( null !== $this->tax_percentage ) {
284 1
			$object->taxPercentage = $this->tax_percentage;
285
		}
286
287 2
		return $object;
288
	}
289
}
290