LineItem::set_quantity()   A
last analyzed

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