Completed
Push — master ( 24a86a...771b97 )
by Aimeos
10:31
created

Standard   A

Complexity

Total Complexity 36

Size/Duplication

Total Lines 270
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 270
rs 9.52
c 0
b 0
f 0
wmc 36
lcom 1
cbo 2

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getOrderBaseId() 0 6 2
A setOrderBaseId() 0 10 2
A getOrderProductId() 0 6 2
A setOrderProductId() 0 10 2
A getDateNext() 0 6 2
A setDateNext() 0 10 2
A getDateEnd() 0 6 2
A setDateEnd() 0 10 2
A getInterval() 0 6 2
A setInterval() 0 14 3
A getStatus() 0 6 2
A setStatus() 0 10 2
A getResourceType() 0 4 1
B fromArray() 0 21 8
A toArray() 0 13 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018
6
 * @package MShop
7
 * @subpackage Subscription
8
 */
9
10
11
namespace Aimeos\MShop\Subscription\Item;
12
13
14
/**
15
 * Default implementation of subscription item
16
 *
17
 * @package MShop
18
 * @subpackage Subscription
19
 */
20
class Standard
21
	extends \Aimeos\MShop\Common\Item\Base
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
22
	implements \Aimeos\MShop\Subscription\Item\Iface
23
{
24
	private $values;
25
26
27
	/**
28
	 * Initializes the object with the given values.
29
	 *
30
	 * @param array $values Associative list of values from database
31
	 */
32
	public function __construct( array $values = [] )
33
	{
34
		parent::__construct( 'subscription.', $values );
35
36
		$this->values = $values;
37
	}
38
39
40
	/**
41
	 * Returns the ID of the base order
42
	 *
43
	 * @return string ID of the base order
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
44
	 */
45
	public function getOrderBaseId()
46
	{
47
		if( isset( $this->values['subscription.ordbaseid'] ) ) {
48
			return (string) $this->values['subscription.ordbaseid'];
49
		}
50
	}
51
52
53
	/**
54
	 * Sets the ID of the base order item which the customer bought
55
	 *
56
	 * @param string $id ID of the base order
57
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
58
	 */
59
	public function setOrderBaseId( $id )
60
	{
61
		if( (string) $id !== $this->getOrderBaseId() )
62
		{
63
			$this->values['subscription.ordbaseid'] = (string) $id;
64
			$this->setModified();
65
		}
66
67
		return $this;
68
	}
69
70
71
	/**
72
	 * Returns the ID of the ordered product
73
	 *
74
	 * @return string ID of the ordered product
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
75
	 */
76
	public function getOrderProductId()
77
	{
78
		if( isset( $this->values['subscription.ordprodid'] ) ) {
79
			return (string) $this->values['subscription.ordprodid'];
80
		}
81
	}
82
83
84
	/**
85
	 * Sets the ID of the ordered product item which the customer subscribed for
86
	 *
87
	 * @param string $id ID of the ordered product
88
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
89
	 */
90
	public function setOrderProductId( $id )
91
	{
92
		if( (string) $id !== $this->getOrderProductId() )
93
		{
94
			$this->values['subscription.ordprodid'] = (string) $id;
95
			$this->setModified();
96
		}
97
98
		return $this;
99
	}
100
101
102
	/**
103
	 * Returns the date of the next subscription renewal
104
	 *
105
	 * @return string ISO date in "YYYY-MM-DD HH:mm:ss" format
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
106
	 */
107
	public function getDateNext()
108
	{
109
		if( isset( $this->values['subscription.datenext'] ) ) {
110
			return (string) $this->values['subscription.datenext'];
111
		}
112
	}
113
114
115
	/**
116
	 * Sets the date of the next subscription renewal
117
	 *
118
	 * @param string $date ISO date in "YYYY-MM-DD HH:mm:ss" format
119
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
120
	 */
121
	public function setDateNext( $date )
122
	{
123
		if( (string) $date !== $this->getDateNext() )
124
		{
125
			$this->values['subscription.datenext'] = $this->checkDateFormat( $date );
126
			$this->setModified();
127
		}
128
129
		return $this;
130
	}
131
132
133
	/**
134
	 * Returns the date when the subscription renewal ends
135
	 *
136
	 * @return string|null ISO date in "YYYY-MM-DD HH:mm:ss" format
137
	 */
138
	public function getDateEnd()
139
	{
140
		if( isset( $this->values['subscription.dateend'] ) ) {
141
			return (string) $this->values['subscription.dateend'];
142
		}
143
	}
144
145
146
	/**
147
	 * Sets the delivery date of the invoice.
148
	 *
149
	 * @param string|null $date ISO date in "YYYY-MM-DD HH:mm:ss" format
150
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
151
	 */
152
	public function setDateEnd( $date )
153
	{
154
		if( (string) $date !== $this->getDateEnd() )
155
		{
156
			$this->values['subscription.dateend'] = $this->checkDateFormat( $date );
157
			$this->setModified();
158
		}
159
160
		return $this;
161
	}
162
163
164
	/**
165
	 * Returns the time interval to pass between the subscription renewals
166
	 *
167
	 * @return string PHP time interval, e.g. "P1M2W"
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
168
	 */
169
	public function getInterval()
170
	{
171
		if( isset( $this->values['subscription.interval'] ) ) {
172
			return (string) $this->values['subscription.interval'];
173
		}
174
	}
175
176
177
	/**
178
	 * Sets the time interval to pass between the subscription renewals
179
	 *
180
	 * @param string $value PHP time interval, e.g. "P1M2W"
181
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
182
	 */
183
	public function setInterval( $value )
184
	{
185
		if( preg_match( '/^P[0-9]+Y[0-9]+M[0-9]+W[0-9]+D$/', $value ) !== 1 ) {
186
			throw new \Aimeos\MShop\Subscription\Exception( sprintf( 'Invalid time interval format "%1$s"', $value ) );
187
		}
188
189
		if( (string) $value !== $this->getInterval() )
190
		{
191
			$this->values['subscription.interval'] = (string) $value;
192
			$this->setModified();
193
		}
194
195
		return $this;
196
	}
197
198
199
	/**
200
	 * Returns the status of the subscriptions
201
	 *
202
	 * @return integer Subscription status, i.e. "1" for enabled, "0" for disabled
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
203
	 */
204
	public function getStatus()
205
	{
206
		if( isset( $this->values['subscription.status'] ) ) {
207
			return (int) $this->values['subscription.status'];
208
		}
209
	}
210
211
212
	/**
213
	 * Sets the status of the subscriptions
214
	 *
215
	 * @return integer Subscription status, i.e. "1" for enabled, "0" for disabled
216
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
0 ignored issues
show
Documentation introduced by
Should the return type not be Standard?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
217
	 */
218
	public function setStatus( $status )
219
	{
220
		if( (string) $status !== $this->getStatus() )
221
		{
222
			$this->values['subscription.status'] = (int) $status;
223
			$this->setModified();
224
		}
225
226
		return $this;
227
	}
228
229
230
	/**
231
	 * Returns the item type
232
	 *
233
	 * @return string Item type, subtypes are separated by slashes
234
	 */
235
	public function getResourceType()
236
	{
237
		return 'subscription';
238
	}
239
240
241
	/**
242
	 * Sets the item values from the given array.
243
	 *
244
	 * @param array $list Associative list of item keys and their values
245
	 * @return array Associative list of keys and their values that are unknown
246
	 */
247
	public function fromArray( array $list )
248
	{
249
		$unknown = [];
250
		$list = parent::fromArray( $list );
251
252
		foreach( $list as $key => $value )
253
		{
254
			switch( $key )
255
			{
256
				case 'subscription.ordbaseid': $this->setOrderBaseId( $value ); break;
257
				case 'subscription.ordprodid': $this->setOrderProductId( $value ); break;
258
				case 'subscription.datenext': $this->setDateNext( $value ); break;
259
				case 'subscription.dateend': $this->setDateEnd( $value ); break;
260
				case 'subscription.interval': $this->setInterval( $value ); break;
261
				case 'subscription.status': $this->setStatus( $value ); break;
262
				default: $unknown[$key] = $value;
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
263
			}
264
		}
265
266
		return $unknown;
267
	}
268
269
270
	/**
271
	 * Returns the item values as associative list.
272
	 *
273
	 * @param boolean True to return private properties, false for public only
274
	 * @return array Associative list of item properties and their values
275
	 */
276
	public function toArray( $private = false )
277
	{
278
		$list = parent::toArray( $private );
279
280
		$list['subscription.ordbaseid'] = $this->getOrderBaseId();
281
		$list['subscription.ordprodid'] = $this->getOrderProductId();
282
		$list['subscription.datenext'] = $this->getDateNext();
283
		$list['subscription.dateend'] = $this->getDateEnd();
284
		$list['subscription.interval'] = $this->getInterval();
285
		$list['subscription.status'] = $this->getStatus();
286
287
		return $list;
288
	}
289
}
290