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

Standard   A

Complexity

Total Complexity 42

Size/Duplication

Total Lines 333
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 333
rs 9.0399
c 0
b 0
f 0
wmc 42
lcom 1
cbo 2

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getAttributeId() 0 8 2
A setAttributeId() 0 10 2
A getParentId() 0 6 2
A setParentId() 0 10 2
A getType() 0 8 2
A setType() 0 10 2
A getCode() 0 8 2
A setCode() 0 10 2
A getName() 0 8 2
A setName() 0 10 2
A getValue() 0 8 2
A setValue() 0 10 2
A getQuantity() 0 8 2
A setQuantity() 0 10 2
A getResourceType() 0 4 1
A copyFrom() 0 11 1
B fromArray() 0 22 9
A toArray() 0 17 2

How to fix   Complexity   

Complex Class

Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2017
7
 * @package MShop
8
 * @subpackage Order
9
 */
10
11
12
namespace Aimeos\MShop\Order\Item\Base\Service\Attribute;
13
14
15
/**
16
 * Default order item base service attribute.
17
 *
18
 * @package MShop
19
 * @subpackage Order
20
 */
21
class Standard
22
	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...
23
	implements \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface
24
{
25
	private $values;
26
27
28
	/**
29
	 * Initializes the order item base service attribute item.
30
	 *
31
	 * @param array $values Associative array of key/value pairs.
32
	 */
33
	public function __construct( array $values = [] )
34
	{
35
		parent::__construct( 'order.base.service.attribute.', $values );
36
37
		$this->values = $values;
38
	}
39
40
41
	/**
42
	 * Returns the original attribute ID of the service attribute item.
43
	 *
44
	 * @return string Attribute ID of the service attribute item
45
	 */
46
	public function getAttributeId()
47
	{
48
		if( isset( $this->values['order.base.service.attribute.attributeid'] ) ) {
49
			return (string) $this->values['order.base.service.attribute.attributeid'];
50
		}
51
52
		return '';
53
	}
54
55
56
	/**
57
	 * Sets the original attribute ID of the service attribute item.
58
	 *
59
	 * @param string $id Attribute ID of the service attribute item
60
	 * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls
61
	 */
62
	public function setAttributeId( $id )
63
	{
64
		if( (string) $id !== $this->getAttributeId() )
65
		{
66
			$this->values['order.base.service.attribute.attributeid'] = (string) $id;
67
			$this->setModified();
68
		}
69
70
		return $this;
71
	}
72
73
74
	/**
75
	 * Returns the ID of the ordered service item as parent
76
	 *
77
	 * @return string|null ID of the ordered service item
78
	 */
79
	public function getParentId()
80
	{
81
		if( isset( $this->values['order.base.service.attribute.parentid'] ) ) {
82
			return (string) $this->values['order.base.service.attribute.parentid'];
83
		}
84
	}
85
86
87
	/**
88
	 * Sets the ID of the ordered service item as parent
89
	 *
90
	 * @param string $id ID of the ordered service item
91
	 * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls
92
	 */
93
	public function setParentId( $id )
94
	{
95
		if( (string) $id !== $this->getParentId() )
96
		{
97
			$this->values['order.base.service.attribute.parentid'] = (string) $id;
98
			$this->setModified();
99
		}
100
101
		return $this;
102
	}
103
104
105
	/**
106
	 * Returns the type of the service attribute item.
107
	 *
108
	 * @return string Type of the service attribute item
109
	 */
110
	public function getType()
111
	{
112
		if( isset( $this->values['order.base.service.attribute.type'] ) ) {
113
			return (string) $this->values['order.base.service.attribute.type'];
114
		}
115
116
		return '';
117
	}
118
119
120
	/**
121
	 * Sets a new type for the service attribute item.
122
	 *
123
	 * @param string $type Type of the service attribute
124
	 * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls
125
	 */
126
	public function setType( $type )
127
	{
128
		if( (string) $type !== $this->getType() )
129
		{
130
			$this->values['order.base.service.attribute.type'] = (string) $type;
131
			$this->setModified();
132
		}
133
134
		return $this;
135
	}
136
137
138
	/**
139
	 * Returns the code of the service attribute item.
140
	 *
141
	 * @return string Code of the service attribute item
142
	 */
143
	public function getCode()
144
	{
145
		if( isset( $this->values['order.base.service.attribute.code'] ) ) {
146
			return (string) $this->values['order.base.service.attribute.code'];
147
		}
148
149
		return '';
150
	}
151
152
153
	/**
154
	 * Sets a new code for the service attribute item.
155
	 *
156
	 * @param string $code Code as defined by the service provider
157
	 * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls
158
	 */
159
	public function setCode( $code )
160
	{
161
		if( (string) $code !== $this->getCode() )
162
		{
163
			$this->values['order.base.service.attribute.code'] = (string) $this->checkCode( $code );
164
			$this->setModified();
165
		}
166
167
		return $this;
168
	}
169
170
171
	/**
172
	 * Returns the name of the service attribute item.
173
	 *
174
	 * @return string Name of the service attribute item
175
	 */
176
	public function getName()
177
	{
178
		if( isset( $this->values['order.base.service.attribute.name'] ) ) {
179
			return (string) $this->values['order.base.service.attribute.name'];
180
		}
181
182
		return '';
183
	}
184
185
186
	/**
187
	 * Sets a new name for the service attribute item.
188
	 *
189
	 * @param string $name Name as defined by the service provider
190
	 * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls
191
	 */
192
	public function setName( $name )
193
	{
194
		if( (string) $name !== $this->getName() )
195
		{
196
			$this->values['order.base.service.attribute.name'] = (string) $name;
197
			$this->setModified();
198
		}
199
200
		return $this;
201
	}
202
203
204
	/**
205
	 * Returns the value of the service attribute item.
206
	 *
207
	 * @return string|array Service attribute item value
208
	 */
209
	public function getValue()
210
	{
211
		if( isset( $this->values['order.base.service.attribute.value'] ) ) {
212
			return $this->values['order.base.service.attribute.value'];
213
		}
214
215
		return '';
216
	}
217
218
219
	/**
220
	 * Sets a new value for the service item.
221
	 *
222
	 * @param string|array $value service attribute item value
223
	 * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls
224
	 */
225
	public function setValue( $value )
226
	{
227
		if( $value !== $this->getValue() )
228
		{
229
			$this->values['order.base.service.attribute.value'] = $value;
230
			$this->setModified();
231
		}
232
233
		return $this;
234
	}
235
236
237
	/**
238
	 * Returns the quantity of the service attribute.
239
	 *
240
	 * @return integer Quantity of the service attribute
241
	 */
242
	public function getQuantity()
243
	{
244
		if( isset( $this->values['order.base.service.attribute.quantity'] ) ) {
245
			return (int) $this->values['order.base.service.attribute.quantity'];
246
		}
247
248
		return 1;
249
	}
250
251
252
	/**
253
	 * Sets the quantity of the service attribute.
254
	 *
255
	 * @param integer $value Quantity of the service attribute
256
	 * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface Order base service attribute 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...
257
	 */
258
	public function setQuantity( $value )
259
	{
260
		if( (int) $value !== $this->getQuantity() )
261
		{
262
			$this->values['order.base.service.attribute.quantity'] = (int) $value;
263
			$this->setModified();
264
		}
265
266
		return $this;
267
	}
268
269
270
	/**
271
	 * Returns the item type
272
	 *
273
	 * @return string Item type, subtypes are separated by slashes
274
	 */
275
	public function getResourceType()
276
	{
277
		return 'order/base/service/attribute';
278
	}
279
280
281
	/**
282
	 * Copys all data from a given attribute item.
283
	 *
284
	 * @param \Aimeos\MShop\Attribute\Item\Iface $item Attribute item to copy from
285
	 * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls
286
	 */
287
	public function copyFrom( \Aimeos\MShop\Attribute\Item\Iface $item )
288
	{
289
		$this->setAttributeId( $item->getId() );
290
		$this->setName( $item->getName() );
291
		$this->setCode( $item->getType() );
292
		$this->setValue( $item->getCode() );
293
294
		$this->setModified();
295
296
		return $this;
297
	}
298
299
300
	/**
301
	 * Sets the item values from the given array.
302
	 *
303
	 * @param array $list Associative list of item keys and their values
304
	 * @return array Associative list of keys and their values that are unknown
305
	 */
306
	public function fromArray( array $list )
307
	{
308
		$unknown = [];
309
		$list = parent::fromArray( $list );
310
311
		foreach( $list as $key => $value )
312
		{
313
			switch( $key )
314
			{
315
				case 'order.base.service.attribute.attrid': $this->setAttributeId( $value ); break;
316
				case 'order.base.service.attribute.parentid': $this->setParentId( $value ); break;
317
				case 'order.base.service.attribute.type': $this->setType( $value ); break;
318
				case 'order.base.service.attribute.name': $this->setName( $value ); break;
319
				case 'order.base.service.attribute.code': $this->setCode( $value ); break;
320
				case 'order.base.service.attribute.value': $this->setValue( $value ); break;
321
				case 'order.base.service.attribute.quantity': $this->setQuantity( $value ); break;
322
				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...
323
			}
324
		}
325
326
		return $unknown;
327
	}
328
329
330
	/**
331
	 * Returns the item values as array.
332
	 *
333
	 * @param boolean True to return private properties, false for public only
334
	 * @return array Associative list of item properties and their values
335
	 */
336
	public function toArray( $private = false )
337
	{
338
		$list = parent::toArray( $private );
339
340
		$list['order.base.service.attribute.attrid'] = $this->getAttributeId();
341
		$list['order.base.service.attribute.type'] = $this->getType();
342
		$list['order.base.service.attribute.name'] = $this->getName();
343
		$list['order.base.service.attribute.code'] = $this->getCode();
344
		$list['order.base.service.attribute.value'] = $this->getValue();
345
		$list['order.base.service.attribute.quantity'] = $this->getQuantity();
346
347
		if( $private === true ) {
348
			$list['order.base.service.attribute.parentid'] = $this->getParentId();
349
		}
350
351
		return $list;
352
	}
353
}