Passed
Push — master ( baa5ed...e67b42 )
by Aimeos
05:46
created

Standard::setRefId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2020-2024
6
 * @package MShop
7
 * @subpackage Review
8
 */
9
10
11
namespace Aimeos\MShop\Review\Item;
12
13
14
/**
15
 * Default impelementation of a review item.
16
 *
17
 * @package MShop
18
 * @subpackage Review
19
 */
20
class Standard
21
	extends \Aimeos\MShop\Common\Item\Base
22
	implements \Aimeos\MShop\Review\Item\Iface
23
{
24
	/**
25
	 * Returns the comment for the reviewed item
26
	 *
27
	 * @return string Comment for the reviewed item
28
	 */
29
	public function getComment() : string
30
	{
31
		return (string) $this->get( 'review.comment', '' );
32
	}
33
34
35
	/**
36
	 * Sets the new comment for the reviewed item
37
	 *
38
	 * @param string|null $value New comment for the reviewed item
39
	 * @return \Aimeos\MShop\Review\Item\Iface Review item for chaining method calls
40
	 */
41
	public function setComment( ?string $value ) : \Aimeos\MShop\Review\Item\Iface
42
	{
43
		return $this->set( 'review.comment', strip_tags( $value ) );
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type null; however, parameter $string of strip_tags() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
		return $this->set( 'review.comment', strip_tags( /** @scrutinizer ignore-type */ $value ) );
Loading history...
44
	}
45
46
47
	/**
48
	 * Returns the ID of the reviewer
49
	 *
50
	 * @return string|null ID of the customer item
51
	 */
52
	public function getCustomerId() : ?string
53
	{
54
		return (string) $this->get( 'review.customerid' );
55
	}
56
57
58
	/**
59
	 * Sets the ID of the reviewer
60
	 *
61
	 * @param string $value New ID of the customer item
62
	 * @return \Aimeos\MShop\Review\Item\Iface Review item for chaining method calls
63
	 */
64
	public function setCustomerId( string $value ) : \Aimeos\MShop\Review\Item\Iface
65
	{
66
		return $this->set( 'review.customerid', $value );
67
	}
68
69
70
	/**
71
	 * Returns the domain the review is valid for.
72
	 *
73
	 * @return string Domain name
74
	 */
75
	public function getDomain() : string
76
	{
77
		return (string) $this->get( 'review.domain', '' );
78
	}
79
80
81
	/**
82
	 * Sets the new domain the review is valid for.
83
	 *
84
	 * @param string $value Domain name
85
	 * @return \Aimeos\MShop\Common\Item\Iface Common item for chaining method calls
86
	 */
87
	public function setDomain( string $value ) : \Aimeos\MShop\Common\Item\Iface
88
	{
89
		return $this->set( 'review.domain', $value );
90
	}
91
92
93
	/**
94
	 * Returns the ID of the ordered review
95
	 *
96
	 * @return string|null ID of the ordered review
97
	 */
98
	public function getOrderProductId() : ?string
99
	{
100
		return (string) $this->get( 'review.orderproductid', '' );
101
	}
102
103
104
	/**
105
	 * Sets the ID of the ordered review item which the customer subscribed for
106
	 *
107
	 * @param string $value ID of the ordered review
108
	 * @return \Aimeos\MShop\Review\Item\Iface Review item for chaining method calls
109
	 */
110
	public function setOrderProductId( string $value ) : \Aimeos\MShop\Review\Item\Iface
111
	{
112
		return $this->set( 'review.orderproductid', $value );
113
	}
114
115
116
	/**
117
	 * Returns the name of the reviewer
118
	 *
119
	 * @return string Name of the reviewer
120
	 */
121
	public function getName() : string
122
	{
123
		return (string) $this->get( 'review.name', '' );
124
	}
125
126
127
	/**
128
	 * Sets the new name of the reviewer
129
	 *
130
	 * @param string $value New name of the reviewer
131
	 * @return \Aimeos\MShop\Review\Item\Iface Review item for chaining method calls
132
	 */
133
	public function setName( string $value ) : \Aimeos\MShop\Review\Item\Iface
134
	{
135
		return $this->set( 'review.name', strip_tags( $value ) );
136
	}
137
138
139
	/**
140
	 * Returns the rating for the reviewed item
141
	 *
142
	 * @return int Rating for the reviewed item (higher is better)
143
	 */
144
	public function getRating() : int
145
	{
146
		return (int) $this->get( 'review.rating', 0 );
147
	}
148
149
150
	/**
151
	 * Sets the new rating for the reviewed item
152
	 *
153
	 * @param int $value Rating for the reviewed item (higher is better)
154
	 * @return \Aimeos\MShop\Review\Item\Iface Review item for chaining method calls
155
	 */
156
	public function setRating( int $value ) : \Aimeos\MShop\Review\Item\Iface
157
	{
158
		return $this->set( 'review.rating', min( 5, max( 0, $value ) ) );
159
	}
160
161
162
	/**
163
	 * Returns the reference ID of the reviewed item, like the unique ID of a product item or a customer item
164
	 *
165
	 * @return string Reference ID of the common list item
166
	 */
167
	public function getRefId() : string
168
	{
169
		return (string) $this->get( 'review.refid', '' );
170
	}
171
172
173
	/**
174
	 * Sets the new reference ID of the common list item, like the unique ID of a product item or a customer item
175
	 *
176
	 * @param string $value New reference ID of the common list item
177
	 * @return \Aimeos\MShop\Review\Item\Iface Review item for chaining method calls
178
	 */
179
	public function setRefId( string $value ) : \Aimeos\MShop\Review\Item\Iface
180
	{
181
		return $this->set( 'review.refid', $value );
182
	}
183
184
185
	/**
186
	 * Returns the response to the review
187
	 *
188
	 * @return string Response to the review
189
	 */
190
	public function getResponse() : string
191
	{
192
		return (string) $this->get( 'review.response', '' );
193
	}
194
195
196
	/**
197
	 * Sets the new response to the review
198
	 *
199
	 * @param string|null $value New response to the review
200
	 * @return \Aimeos\MShop\Review\Item\Iface Review item for chaining method calls
201
	 */
202
	public function setResponse( ?string $value ) : \Aimeos\MShop\Review\Item\Iface
203
	{
204
		return $this->set( 'review.response', strip_tags( $value ) );
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type null; however, parameter $string of strip_tags() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

204
		return $this->set( 'review.response', strip_tags( /** @scrutinizer ignore-type */ $value ) );
Loading history...
205
	}
206
207
208
	/**
209
	 * Returns the status of the review item.
210
	 *
211
	 * @return int Status of the review item
212
	 */
213
	public function getStatus() : int
214
	{
215
		return (int) $this->get( 'review.status', 1 );
216
	}
217
218
219
	/**
220
	 * Sets the new status of the review item.
221
	 *
222
	 * @param int $status New status of the review item
223
	 * @return \Aimeos\MShop\Review\Item\Iface Review item for chaining method calls
224
	 */
225
	public function setStatus( int $status ) : \Aimeos\MShop\Common\Item\Iface
226
	{
227
		return $this->set( 'review.status', $status );
228
	}
229
230
231
	/**
232
	 * Tests if the item is available based on status, time, language and currency
233
	 *
234
	 * @return bool True if available, false if not
235
	 */
236
	public function isAvailable() : bool
237
	{
238
		return parent::isAvailable() && $this->getStatus() > 0;
239
	}
240
241
242
	/*
243
	 * Sets the item values from the given array and removes that entries from the list
244
	 *
245
	 * @param array &$list Associative list of item keys and their values
246
	 * @param bool True to set private properties too, false for public only
247
	 * @return \Aimeos\MShop\Common\Item\Iface Common item for chaining method calls
248
	 */
249
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
250
	{
251
		$item = parent::fromArray( $list, $private );
252
253
		foreach( $list as $key => $value )
254
		{
255
			switch( $key )
256
			{
257
				case 'review.orderproductid': !$private ?: $item = $item->setOrderProductId( $value ); break;
258
				case 'review.customerid': !$private ?: $item = $item->setCustomerId( $value ); break;
259
				case 'review.refid': $item = $item->setRefId( $value ); break;
260
				case 'review.domain': $item = $item->setDomain( $value ); break;
261
				case 'review.comment': $item = $item->setComment( $value ); break;
262
				case 'review.response': $item = $item->setResponse( $value ); break;
263
				case 'review.status': $item = $item->setStatus( (int) $value ); break;
264
				case 'review.rating': $item = $item->setRating( (int) $value ); break;
265
				case 'review.name': $item = $item->setName( $value ); break;
266
				default: continue 2;
267
			}
268
269
			unset( $list[$key] );
270
		}
271
272
		return $item;
273
	}
274
275
276
	/**
277
	 * Returns the item values as array.
278
	 *
279
	 * @param bool True to return private properties, false for public only
280
	 * @return array Associative list of item properties and their values
281
	 */
282
	public function toArray( bool $private = false ) : array
283
	{
284
		$list = parent::toArray( $private );
285
286
		$list['review.refid'] = $this->getRefId();
287
		$list['review.domain'] = $this->getDomain();
288
		$list['review.response'] = $this->getResponse();
289
		$list['review.comment'] = $this->getComment();
290
		$list['review.rating'] = $this->getRating();
291
		$list['review.status'] = $this->getStatus();
292
		$list['review.name'] = $this->getName();
293
		$list['review.ctime'] = $this->getTimeCreated();
294
295
		if( $private )
296
		{
297
			$list['review.orderproductid'] = $this->getOrderProductId();
298
			$list['review.customerid'] = $this->getCustomerId();
299
		}
300
301
		return $list;
302
	}
303
}
304