Completed
Push — master ( 1b60f8...d5b5b7 )
by Aimeos
08:48
created

Standard::fromArray()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nc 7
nop 1
dl 0
loc 20
rs 8.2222
c 0
b 0
f 0
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 ordered product
42
	 *
43
	 * @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...
44
	 */
45
	public function getOrderProductId()
46
	{
47
		if( isset( $this->values['subscription.ordprodid'] ) ) {
48
			return (string) $this->values['subscription.ordprodid'];
49
		}
50
	}
51
52
53
	/**
54
	 * Sets the ID of the ordered product item which the customer subscribed for
55
	 *
56
	 * @param string $id ID of the ordered product
57
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
58
	 */
59
	public function setOrderProductId( $id )
60
	{
61
		if( (string) $id !== $this->getOrderProductId() )
62
		{
63
			$this->values['subscription.ordprodid'] = (string) $id;
64
			$this->setModified();
65
		}
66
67
		return $this;
68
	}
69
70
71
	/**
72
	 * Returns the date of the next subscription renewal
73
	 *
74
	 * @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...
75
	 */
76
	public function getDateNext()
77
	{
78
		if( isset( $this->values['subscription.datenext'] ) ) {
79
			return (string) $this->values['subscription.datenext'];
80
		}
81
	}
82
83
84
	/**
85
	 * Sets the date of the next subscription renewal
86
	 *
87
	 * @param string $date ISO date in "YYYY-MM-DD HH:mm:ss" format
88
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
89
	 */
90
	public function setDateNext( $date )
91
	{
92
		if( (string) $date !== $this->getDateNext() )
93
		{
94
			$this->values['subscription.datenext'] = $this->checkDateFormat( $date );
95
			$this->setModified();
96
		}
97
98
		return $this;
99
	}
100
101
102
	/**
103
	 * Returns the date when the subscription renewal ends
104
	 *
105
	 * @return string|null ISO date in "YYYY-MM-DD HH:mm:ss" format
106
	 */
107
	public function getDateEnd()
108
	{
109
		if( isset( $this->values['subscription.dateend'] ) ) {
110
			return (string) $this->values['subscription.dateend'];
111
		}
112
	}
113
114
115
	/**
116
	 * Sets the delivery date of the invoice.
117
	 *
118
	 * @param string|null $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 setDateEnd( $date )
122
	{
123
		if( (string) $date !== $this->getDateEnd() )
124
		{
125
			$this->values['subscription.dateend'] = $this->checkDateFormat( $date );
126
			$this->setModified();
127
		}
128
129
		return $this;
130
	}
131
132
133
	/**
134
	 * Returns the time interval to pass between the subscription renewals
135
	 *
136
	 * @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...
137
	 */
138
	public function getInterval()
139
	{
140
		if( isset( $this->values['subscription.interval'] ) ) {
141
			return (string) $this->values['subscription.interval'];
142
		}
143
	}
144
145
146
	/**
147
	 * Sets the time interval to pass between the subscription renewals
148
	 *
149
	 * @param string $value PHP time interval, e.g. "P1M2W"
150
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
151
	 */
152
	public function setInterval( $value )
153
	{
154
		if( (string) $value !== $this->getInterval() )
155
		{
156
			$this->values['subscription.interval'] = (string) $value;
157
			$this->setModified();
158
		}
159
160
		return $this;
161
	}
162
163
164
	/**
165
	 * Returns the status of the subscriptions
166
	 *
167
	 * @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...
168
	 */
169
	public function getStatus()
170
	{
171
		if( isset( $this->values['subscription.status'] ) ) {
172
			return (int) $this->values['subscription.status'];
173
		}
174
	}
175
176
177
	/**
178
	 * Sets the status of the subscriptions
179
	 *
180
	 * @return integer Subscription status, i.e. "1" for enabled, "0" for disabled
181
	 * @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...
182
	 */
183
	public function setStatus( $status )
184
	{
185
		if( (string) $status !== $this->getStatus() )
186
		{
187
			$this->values['subscription.status'] = (int) $status;
188
			$this->setModified();
189
		}
190
191
		return $this;
192
	}
193
194
195
	/**
196
	 * Returns the item type
197
	 *
198
	 * @return string Item type, subtypes are separated by slashes
199
	 */
200
	public function getResourceType()
201
	{
202
		return 'subscription';
203
	}
204
205
206
	/**
207
	 * Sets the item values from the given array.
208
	 *
209
	 * @param array $list Associative list of item keys and their values
210
	 * @return array Associative list of keys and their values that are unknown
211
	 */
212
	public function fromArray( array $list )
213
	{
214
		$unknown = [];
215
		$list = parent::fromArray( $list );
216
217
		foreach( $list as $key => $value )
218
		{
219
			switch( $key )
220
			{
221
				case 'subscription.ordprodid': $this->setOrderProductId( $value ); break;
222
				case 'subscription.datenext': $this->setDateNext( $value ); break;
223
				case 'subscription.dateend': $this->setDateEnd( $value ); break;
224
				case 'subscription.interval': $this->setInterval( $value ); break;
225
				case 'subscription.status': $this->setStatus( $value ); break;
226
				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...
227
			}
228
		}
229
230
		return $unknown;
231
	}
232
233
234
	/**
235
	 * Returns the item values as associative list.
236
	 *
237
	 * @param boolean True to return private properties, false for public only
238
	 * @return array Associative list of item properties and their values
239
	 */
240
	public function toArray( $private = false )
241
	{
242
		$list = parent::toArray( $private );
243
244
		$list['subscription.ordprodid'] = $this->getOrderProductId();
245
		$list['subscription.datenext'] = $this->getDateNext();
246
		$list['subscription.dateend'] = $this->getDateEnd();
247
		$list['subscription.interval'] = $this->getInterval();
248
		$list['subscription.status'] = $this->getStatus();
249
250
		return $list;
251
	}
252
}
253