Passed
Push — master ( 62fc03...bcc204 )
by Aimeos
04:26
created

Standard::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2024
6
 * @package MShop
7
 * @subpackage Order
8
 */
9
10
11
namespace Aimeos\MShop\Order\Item;
12
13
14
/**
15
 * Default implementation of an order invoice item.
16
 *
17
 * @property int oldPaymentStatus Last delivery status before it was changed by setDeliveryStatus()
18
 * @property int oldDeliveryStatus Last payment status before it was changed by setPaymentStatus()
19
 *
20
 * @package MShop
21
 * @subpackage Order
22
 */
23
class Standard
24
	extends \Aimeos\MShop\Order\Item\Base
25
	implements \Aimeos\MShop\Order\Item\Iface
26
{
27
	/**
28
	 * Returns the order number
29
	 *
30
	 * @return string Order number
31
	 */
32
	public function getOrderNumber() : string
33
	{
34
		if( self::macro( 'ordernumber' ) ) {
35
			return (string) $this->call( 'ordernumber' );
36
		}
37
38
		return (string) $this->getId();
39
	}
40
41
42
	/**
43
	 * Returns the number of the invoice.
44
	 *
45
	 * @return string Invoice number
46
	 */
47
	public function getInvoiceNumber() : string
48
	{
49
		if( self::macro( 'invoicenumber' ) ) {
50
			return (string) $this->call( 'invoicenumber' );
51
		}
52
53
		return (string) $this->get( 'order.invoiceno', '' );
54
	}
55
56
57
	/**
58
	 * Sets the number of the invoice.
59
	 *
60
	 * @param string|null $value Invoice number
61
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
62
	 */
63
	public function setInvoiceNumber( ?string $value ) : \Aimeos\MShop\Common\Item\Iface
64
	{
65
		return $this->set( 'order.invoiceno', (string) $value );
66
	}
67
68
69
	/**
70
	 * Returns the channel of the invoice (repeating, web, phone, etc).
71
	 *
72
	 * @return string Invoice channel
73
	 */
74
	public function getChannel() : string
75
	{
76
		return (string) $this->get( 'order.channel', '' );
77
	}
78
79
80
	/**
81
	 * Sets the channel of the invoice.
82
	 *
83
	 * @param string|null $channel Invoice channel
84
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
85
	 */
86
	public function setChannel( ?string $channel ) : \Aimeos\MShop\Common\Item\Iface
87
	{
88
		return $this->set( 'order.channel', $this->checkCode( (string) $channel ) );
89
	}
90
91
92
	/**
93
	 * Returns the delivery date of the invoice.
94
	 *
95
	 * @return string|null ISO date in yyyy-mm-dd HH:ii:ss format
96
	 */
97
	public function getDateDelivery() : ?string
98
	{
99
		$value = $this->get( 'order.datedelivery' );
100
		return $value ? substr( $value, 0, 19 ) : null;
101
	}
102
103
104
	/**
105
	 * Sets the delivery date of the invoice.
106
	 *
107
	 * @param string|null $date ISO date in yyyy-mm-dd HH:ii:ss format
108
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
109
	 */
110
	public function setDateDelivery( ?string $date ) : \Aimeos\MShop\Order\Item\Iface
111
	{
112
		return $this->set( 'order.datedelivery', $this->checkDateFormat( $date ) );
113
	}
114
115
116
	/**
117
	 * Returns the purchase date of the invoice.
118
	 *
119
	 * @return string|null ISO date in yyyy-mm-dd HH:ii:ss format
120
	 */
121
	public function getDatePayment() : ?string
122
	{
123
		$value = $this->get( 'order.datepayment' );
124
		return $value ? substr( $value, 0, 19 ) : null;
125
	}
126
127
128
	/**
129
	 * Sets the purchase date of the invoice.
130
	 *
131
	 * @param string|null $date ISO date in yyyy-mm-dd HH:ii:ss format
132
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
133
	 */
134
	public function setDatePayment( ?string $date ) : \Aimeos\MShop\Order\Item\Iface
135
	{
136
		return $this->set( 'order.datepayment', $this->checkDateFormat( $date ) );
137
	}
138
139
140
	/**
141
	 * Returns the delivery status of the invoice.
142
	 *
143
	 * @return int Status code constant from \Aimeos\MShop\Order\Item\Base
144
	 */
145
	public function getStatusDelivery() : int
146
	{
147
		return $this->get( 'order.statusdelivery', -1 );
148
	}
149
150
151
	/**
152
	 * Sets the delivery status of the invoice.
153
	 *
154
	 * @param int $status Status code constant from \Aimeos\MShop\Order\Item\Base
155
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
156
	 */
157
	public function setStatusDelivery( int $status ) : \Aimeos\MShop\Order\Item\Iface
158
	{
159
		$this->set( '.statusdelivery', $this->get( 'order.statusdelivery' ) );
160
		return $this->set( 'order.statusdelivery', $status );
161
	}
162
163
164
	/**
165
	 * Returns the payment status of the invoice.
166
	 *
167
	 * @return int Payment constant from \Aimeos\MShop\Order\Item\Base
168
	 */
169
	public function getStatusPayment() : int
170
	{
171
		return $this->get( 'order.statuspayment', -1 );
172
	}
173
174
175
	/**
176
	 * Sets the payment status of the invoice.
177
	 *
178
	 * @param int $status Payment constant from \Aimeos\MShop\Order\Item\Base
179
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
180
	 */
181
	public function setStatusPayment( int $status ) : \Aimeos\MShop\Order\Item\Iface
182
	{
183
		if( $status !== $this->getStatusPayment() ) {
184
			$this->set( 'order.datepayment', date( 'Y-m-d H:i:s' ) );
185
		}
186
187
		$this->set( '.statuspayment', $this->get( 'order.statuspayment' ) );
188
		return $this->set( 'order.statuspayment', $status );
189
	}
190
191
192
	/**
193
	 * Returns the related invoice ID.
194
	 *
195
	 * @return string Related invoice ID
196
	 */
197
	public function getRelatedId() : string
198
	{
199
		return (string) $this->get( 'order.relatedid', '' );
200
	}
201
202
203
	/**
204
	 * Sets the related invoice ID.
205
	 *
206
	 * @param string|null $id Related invoice ID
207
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
208
	 * @throws \Aimeos\MShop\Order\Exception If ID is invalid
209
	 */
210
	public function setRelatedId( ?string $id ) : \Aimeos\MShop\Order\Item\Iface
211
	{
212
		return $this->set( 'order.relatedid', (string) $id );
213
	}
214
215
216
	/**
217
	 * Returns the associated customer item
218
	 *
219
	 * @return \Aimeos\MShop\Customer\Item\Iface|null Customer item
220
	 */
221
	public function getCustomerItem() : ?\Aimeos\MShop\Customer\Item\Iface
222
	{
223
		return $this->customer;
224
	}
225
226
227
	/**
228
	 * Returns the code of the site the item is stored.
229
	 *
230
	 * @return string Site code (or empty string if not available)
231
	 */
232
	public function getSiteCode() : string
233
	{
234
		return $this->get( 'order.sitecode', '' );
235
	}
236
237
238
	/**
239
	 * Returns the comment field of the order item.
240
	 *
241
	 * @return string Comment for the order
242
	 */
243
	public function getComment() : string
244
	{
245
		return $this->get( 'order.comment', '' );
246
	}
247
248
249
	/**
250
	 * Sets the comment field of the order item
251
	 *
252
	 * @param string|null $comment Comment for the order
253
	 * @return \Aimeos\MShop\Order\Item\Iface Order base item for chaining method calls
254
	 */
255
	public function setComment( ?string $comment ) : \Aimeos\MShop\Order\Item\Iface
256
	{
257
		return $this->set( 'order.comment', (string) $comment );
258
	}
259
260
261
	/**
262
	 * Returns the customer ID of the customer who has ordered.
263
	 *
264
	 * @return string Unique ID of the customer
265
	 */
266
	public function getCustomerId() : string
267
	{
268
		return $this->get( 'order.customerid', '' );
269
	}
270
271
272
	/**
273
	 * Sets the customer ID of the customer who has ordered.
274
	 *
275
	 * @param string|null $customerid Unique ID of the customer
276
	 * @return \Aimeos\MShop\Order\Item\Iface Order base item for chaining method calls
277
	 */
278
	public function setCustomerId( ?string $customerid ) : \Aimeos\MShop\Order\Item\Iface
279
	{
280
		if( (string) $customerid !== $this->getCustomerId() )
281
		{
282
			$this->notify( 'setCustomerId.before', (string) $customerid );
283
			$this->set( 'order.customerid', (string) $customerid );
284
			$this->notify( 'setCustomerId.after', (string) $customerid );
285
		}
286
287
		return $this;
288
	}
289
290
291
	/**
292
	 * Returns the customer reference field of the order item
293
	 *
294
	 * @return string Customer reference for the order
295
	 */
296
	public function getCustomerReference() : string
297
	{
298
		return $this->get( 'order.customerref', '' );
299
	}
300
301
302
	/**
303
	 * Sets the customer reference field of the order item
304
	 *
305
	 * @param string|null $value Customer reference for the order
306
	 * @return \Aimeos\MShop\Order\Item\Iface Order base item for chaining method calls
307
	 */
308
	public function setCustomerReference( ?string $value ) : \Aimeos\MShop\Order\Item\Iface
309
	{
310
		return $this->set( 'order.customerref', (string) $value );
311
	}
312
313
314
	/*
315
	 * Sets the item values from the given array and removes that entries from the list
316
	 *
317
	 * @param array &$list Associative list of item keys and their values
318
	 * @param bool True to set private properties too, false for public only
319
	 * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls
320
	 */
321
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
322
	{
323
		$item = parent::fromArray( $list, $private );
324
325
		foreach( $list as $key => $value )
326
		{
327
			switch( $key )
328
			{
329
				case 'order.channel': !$private ?: $item->setChannel( $value ); break;
330
				case 'order.invoiceno': !$private ?: $item->setInvoiceNumber( $value ); break;
331
				case 'order.statusdelivery': !$private ?: $item->setStatusDelivery( (int) $value ); break;
332
				case 'order.statuspayment': !$private ?: $item->setStatusPayment( (int) $value ); break;
333
				case 'order.datedelivery': !$private ?: $item->setDateDelivery( $value ); break;
334
				case 'order.datepayment': !$private ?: $item->setDatePayment( $value ); break;
335
				case 'order.customerid': !$private ?: $item->setCustomerId( $value ); break;
336
				case 'order.customerref': $item->setCustomerReference( $value ); break;
337
				case 'order.languageid': $item->locale()->setLanguageId( $value ); break;
338
				case 'order.relatedid': $item->setRelatedId( $value ); break;
339
				case 'order.comment': $item->setComment( $value ); break;
340
				default: continue 2;
341
			}
342
343
			unset( $list[$key] );
344
		}
345
346
		return $item;
347
	}
348
349
350
	/**
351
	 * Returns the item values as array.
352
	 *
353
	 * @param bool True to return private properties, false for public only
354
	 * @return array Associative list of item properties and their values
355
	 */
356
	public function toArray( bool $private = false ) : array
357
	{
358
		$list = parent::toArray( $private );
359
360
		$list['order.channel'] = $this->getChannel();
361
		$list['order.invoiceno'] = $this->getInvoiceNumber();
362
		$list['order.statusdelivery'] = $this->getStatusDelivery();
363
		$list['order.statuspayment'] = $this->getStatusPayment();
364
		$list['order.datedelivery'] = $this->getDateDelivery();
365
		$list['order.datepayment'] = $this->getDatePayment();
366
		$list['order.relatedid'] = $this->getRelatedId();
367
		$list['order.sitecode'] = $this->getSiteCode();
368
		$list['order.customerid'] = $this->getCustomerId();
369
		$list['order.languageid'] = $this->locale()->getLanguageId();
370
		$list['order.customerref'] = $this->getCustomerReference();
371
		$list['order.comment'] = $this->getComment();
372
373
		return $list;
374
	}
375
}
376