• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aimeos / aimeos-core / 18a2821b-9fed-4e27-8151-60c5375acb47

16 Aug 2024 11:47AM UTC coverage: 91.965% (-0.002%) from 91.967%
18a2821b-9fed-4e27-8151-60c5375acb47

push

circleci

aimeos
Removed unnecessary assignments in fromArray()

278 of 279 new or added lines in 40 files covered. (99.64%)

30 existing lines in 30 files now uncovered.

10244 of 11139 relevant lines covered (91.97%)

61.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/src/MShop/Subscription/Item/Standard.php
1
<?php
2

3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2024
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
22
        implements \Aimeos\MShop\Subscription\Item\Iface
23
{
24
        /**
25
         * Returns the associated order item
26
         *
27
         * @return \Aimeos\MShop\Order\Item\Iface|null Order item
28
         */
29
        public function getOrderItem() : ?\Aimeos\MShop\Order\Item\Iface
30
        {
31
                return $this->get( '.orderitem' );
3✔
32
        }
33

34

35
        /**
36
         * Returns the ID of the order
37
         *
38
         * @return string|null ID of the order
39
         */
40
        public function getOrderId() : ?string
41
        {
42
                return $this->get( 'subscription.orderid' );
5✔
43
        }
44

45

46
        /**
47
         * Sets the ID of the order item which the customer bought
48
         *
49
         * @param string $id ID of the order
50
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
51
         */
52
        public function setOrderId( string $id ) : \Aimeos\MShop\Subscription\Item\Iface
53
        {
54
                return $this->set( 'subscription.orderid', $id );
2✔
55
        }
56

57

58
        /**
59
         * Returns the ID of the ordered product
60
         *
61
         * @return string|null ID of the ordered product
62
         */
63
        public function getOrderProductId() : ?string
64
        {
65
                return $this->get( 'subscription.ordprodid' );
5✔
66
        }
67

68

69
        /**
70
         * Sets the ID of the ordered product item which the customer subscribed for
71
         *
72
         * @param string $id ID of the ordered product
73
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
74
         */
75
        public function setOrderProductId( string $id ) : \Aimeos\MShop\Subscription\Item\Iface
76
        {
77
                return $this->set( 'subscription.ordprodid', $id );
2✔
78
        }
79

80

81
        /**
82
         * Returns the date of the next subscription renewal
83
         *
84
         * @return string|null ISO date in "YYYY-MM-DD HH:mm:ss" format
85
         */
86
        public function getDateNext() : ?string
87
        {
88
                $value = $this->get( 'subscription.datenext' );
5✔
89
                return $value ? substr( $value, 0, 19 ) : null;
5✔
90
        }
91

92

93
        /**
94
         * Sets the date of the next subscription renewal
95
         *
96
         * @param string $date ISO date in "YYYY-MM-DD HH:mm:ss" format
97
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
98
         */
99
        public function setDateNext( string $date ) : \Aimeos\MShop\Subscription\Item\Iface
100
        {
101
                return $this->set( 'subscription.datenext', $this->checkDateFormat( $date ) );
2✔
102
        }
103

104

105
        /**
106
         * Returns the date when the subscription renewal ends
107
         *
108
         * @return string|null ISO date in "YYYY-MM-DD HH:mm:ss" format
109
         */
110
        public function getDateEnd() : ?string
111
        {
112
                $value = $this->get( 'subscription.dateend' );
5✔
113
                return $value ? substr( $value, 0, 19 ) : null;
5✔
114
        }
115

116

117
        /**
118
         * Sets the delivery date of the invoice.
119
         *
120
         * @param string|null $date ISO date in "YYYY-MM-DD HH:mm:ss" format
121
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
122
         */
123
        public function setDateEnd( ?string $date ) : \Aimeos\MShop\Subscription\Item\Iface
124
        {
125
                return $this->set( 'subscription.dateend', $this->checkDateFormat( $date ) );
2✔
126
        }
127

128

129
        /**
130
         * Returns the time interval to pass between the subscription renewals
131
         *
132
         * @return string PHP time interval, e.g. "P1M2W"
133
         */
134
        public function getInterval() : string
135
        {
136
                return $this->get( 'subscription.interval', '' );
5✔
137
        }
138

139

140
        /**
141
         * Sets the time interval to pass between the subscription renewals
142
         *
143
         * @param string $value PHP time interval, e.g. "P1M2W"
144
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
145
         */
146
        public function setInterval( string $value ) : \Aimeos\MShop\Subscription\Item\Iface
147
        {
148
                if( strlen( $value ) > 1 && preg_match( '/^P([0-9]+Y)?([0-9]+M)?([0-9]+W)?([0-9]+D)?(T?[0-9]+H)?$/', $value ) !== 1 ) {
3✔
149
                        throw new \Aimeos\MShop\Subscription\Exception( sprintf( 'Invalid time interval format "%1$s"', $value ) );
×
150
                }
151

152
                return $this->set( 'subscription.interval', $value );
3✔
153
        }
154

155

156
        /**
157
         * Returns the current renewal period of the subscription product
158
         *
159
         * @return int Current renewal period
160
         */
161
        public function getPeriod() : int
162
        {
163
                return $this->get( 'subscription.period', 1 );
5✔
164
        }
165

166

167
        /**
168
         * Sets the current renewal period of the subscription product
169
         *
170
         * @param int $value Current renewal period
171
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
172
         */
173
        public function setPeriod( int $value ) : \Aimeos\MShop\Subscription\Item\Iface
174
        {
175
                return $this->set( 'subscription.period', $value );
2✔
176
        }
177

178

179
        /**
180
         * Returns the product ID of the subscription product
181
         *
182
         * @return string Product ID
183
         */
184
        public function getProductId() : string
185
        {
186
                return $this->get( 'subscription.productid', '' );
5✔
187
        }
188

189

190
        /**
191
         * Sets the product ID of the subscription product
192
         *
193
         * @param string $value Product ID
194
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
195
         */
196
        public function setProductId( string $value ) : \Aimeos\MShop\Subscription\Item\Iface
197
        {
198
                return $this->set( 'subscription.productid', $value );
2✔
199
        }
200

201

202
        /**
203
         * Returns the reason for the end of the subscriptions
204
         *
205
         * @return int|null Reason code or NULL for no reason
206
         */
207
        public function getReason() : ?int
208
        {
209
                return $this->get( 'subscription.reason' );
7✔
210
        }
211

212

213
        /**
214
         * Sets the reason for the end of the subscriptions
215
         *
216
         * @param int|null $value Reason code or NULL for no reason
217
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
218
         */
219
        public function setReason( ?int $value ) : \Aimeos\MShop\Subscription\Item\Iface
220
        {
221
                return $this->set( 'subscription.reason', $value );
4✔
222
        }
223

224

225
        /**
226
         * Returns the status of the subscriptions
227
         *
228
         * @return int Subscription status, i.e. "1" for enabled, "0" for disabled
229
         */
230
        public function getStatus() : int
231
        {
232
                return $this->get( 'subscription.status', 1 );
5✔
233
        }
234

235

236
        /**
237
         * Sets the status of the subscriptions
238
         *
239
         * @return int Subscription status, i.e. "1" for enabled, "0" for disabled
240
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
241
         */
242
        public function setStatus( int $status ) : \Aimeos\MShop\Subscription\Item\Iface
243
        {
244
                return $this->set( 'subscription.status', $status );
2✔
245
        }
246

247

248
        /*
249
         * Sets the item values from the given array and removes that entries from the list
250
         *
251
         * @param array &$list Associative list of item keys and their values
252
         * @param bool True to set private properties too, false for public only
253
         * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item for chaining method calls
254
         */
255
        public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
256
        {
257
                $item = parent::fromArray( $list, $private );
1✔
258

259
                foreach( $list as $key => $value )
1✔
260
                {
261
                        switch( $key )
262
                        {
263
                                case 'subscription.orderid': $item->setOrderId( $value ); break;
1✔
264
                                case 'subscription.ordprodid': $item->setOrderProductId( $value ); break;
1✔
265
                                case 'subscription.productid': $item->setProductId( $value ); break;
1✔
266
                                case 'subscription.datenext': $item->setDateNext( $value ); break;
1✔
267
                                case 'subscription.dateend': $item->setDateEnd( $value ); break;
1✔
268
                                case 'subscription.interval': $item->setInterval( $value ); break;
1✔
269
                                case 'subscription.period': $item->setPeriod( (int) $value ); break;
1✔
270
                                case 'subscription.status': $item->setStatus( (int) $value ); break;
1✔
271
                                case 'subscription.reason': $item->setReason( $value !== null ? (int) $value : null ); break;
1✔
UNCOV
272
                                default: continue 2;
×
273
                        }
274

275
                        unset( $list[$key] );
1✔
276
                }
277

278
                return $item;
1✔
279
        }
280

281

282
        /**
283
         * Returns the item values as associative list.
284
         *
285
         * @param bool True to return private properties, false for public only
286
         * @return array Associative list of item properties and their values
287
         */
288
        public function toArray( bool $private = false ) : array
289
        {
290
                $list = parent::toArray( $private );
2✔
291

292
                $list['subscription.orderid'] = $this->getOrderId();
2✔
293
                $list['subscription.ordprodid'] = $this->getOrderProductId();
2✔
294
                $list['subscription.productid'] = $this->getProductId();
2✔
295
                $list['subscription.datenext'] = $this->getDateNext();
2✔
296
                $list['subscription.dateend'] = $this->getDateEnd();
2✔
297
                $list['subscription.interval'] = $this->getInterval();
2✔
298
                $list['subscription.period'] = $this->getPeriod();
2✔
299
                $list['subscription.status'] = $this->getStatus();
2✔
300
                $list['subscription.reason'] = $this->getReason();
2✔
301

302
                return $list;
2✔
303
        }
304
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc