Passed
Push — master ( 8c3433...5fb848 )
by Aimeos
16:39
created

Standard   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 24
dl 0
loc 120
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 18 6
A setType() 0 3 1
A getType() 0 3 1
A getParentId() 0 3 1
A setParentId() 0 3 1
A getValue() 0 3 1
A setValue() 0 3 1
A toArray() 0 12 2
1
<?php
2
/**
3
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
4
 * @copyright Aimeos (aimeos.org), 2015-2024
5
 * @package MShop
6
 * @subpackage Order
7
 */
8
9
10
namespace Aimeos\MShop\Order\Item\Status;
11
12
13
/**
14
 * Default implementation of the order status object.
15
 *
16
 * @package MShop
17
 * @subpackage Order
18
 */
19
class Standard
20
	extends \Aimeos\MShop\Order\Item\Status\Base
21
	implements \Aimeos\MShop\Order\Item\Status\Iface
22
{
23
	/**
24
	 * Returns the parentid of the order status.
25
	 *
26
	 * @return string|null Parent ID of the order
27
	 */
28
	public function getParentId() : ?string
29
	{
30
		return $this->get( 'order.status.parentid' );
31
	}
32
33
34
	/**
35
	 * Sets the parentid of the order status.
36
	 *
37
	 * @param string|null $parentid Parent ID of the order status
38
	 * @return \Aimeos\MShop\Order\Item\Status\Iface Order status item for chaining method calls
39
	 */
40
	public function setParentId( ?string $parentid ) : \Aimeos\MShop\Common\Item\Iface
41
	{
42
		return $this->set( 'order.status.parentid', $parentid );
43
	}
44
45
46
	/**
47
	 * Returns the type of the order status.
48
	 *
49
	 * @return string Type of the order status
50
	 */
51
	public function getType() : string
52
	{
53
		return $this->get( 'order.status.type', '' );
54
	}
55
56
57
	/**
58
	 * Sets the type of the order status.
59
	 *
60
	 * @param string $type Type of the order status
61
	 * @return \Aimeos\MShop\Order\Item\Status\Iface Order status item for chaining method calls
62
	 */
63
	public function setType( string $type ) : \Aimeos\MShop\Common\Item\Iface
64
	{
65
		return $this->set( 'order.status.type', $this->checkCode( $type ) );
66
	}
67
68
69
	/**
70
	 * Returns the value of the order status.
71
	 *
72
	 * @return string Value of the order status
73
	 */
74
	public function getValue() : string
75
	{
76
		return (string) $this->get( 'order.status.value', '' );
77
	}
78
79
80
	/**
81
	 * Sets the value of the order status.
82
	 *
83
	 * @param string $value Value of the order status
84
	 * @return \Aimeos\MShop\Order\Item\Status\Iface Order status item for chaining method calls
85
	 */
86
	public function setValue( string $value ) : \Aimeos\MShop\Order\Item\Status\Iface
87
	{
88
		return $this->set( 'order.status.value', $value );
89
	}
90
91
92
	/*
93
	 * Sets the item values from the given array and removes that entries from the list
94
	 *
95
	 * @param array &$list Associative list of item keys and their values
96
	 * @param bool True to set private properties too, false for public only
97
	 * @return \Aimeos\MShop\Order\Item\Status\Iface Order status item for chaining method calls
98
	 */
99
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
100
	{
101
		$item = parent::fromArray( $list, $private );
102
103
		foreach( $list as $key => $value )
104
		{
105
			switch( $key )
106
			{
107
				case 'order.status.parentid': !$private ?: $item = $item->setParentId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setParentId() does not exist on Aimeos\MShop\Order\Item\Status\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

107
				case 'order.status.parentid': !$private ?: $item = $item->/** @scrutinizer ignore-call */ setParentId( $value ); break;
Loading history...
108
				case 'order.status.type': $item = $item->setType( $value ); break;
0 ignored issues
show
Bug introduced by
The method setType() does not exist on Aimeos\MShop\Order\Item\Status\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

108
				case 'order.status.type': /** @scrutinizer ignore-call */ $item = $item->setType( $value ); break;
Loading history...
109
				case 'order.status.value': $item = $item->setValue( $value ); break;
0 ignored issues
show
Bug introduced by
The method setValue() does not exist on Aimeos\MShop\Order\Item\Status\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

109
				case 'order.status.value': /** @scrutinizer ignore-call */ $item = $item->setValue( $value ); break;
Loading history...
110
				default: continue 2;
111
			}
112
113
			unset( $list[$key] );
114
		}
115
116
		return $item;
117
	}
118
119
120
121
	/**
122
	 * Returns the item values as array.
123
	 *
124
	 * @param bool True to return private properties, false for public only
125
	 * @return array Associative list of item properties and their values
126
	 */
127
	public function toArray( bool $private = false ) : array
128
	{
129
		$list = parent::toArray( $private );
130
131
		$list['order.status.type'] = $this->getType();
132
		$list['order.status.value'] = $this->getValue();
133
134
		if( $private === true ) {
135
			$list['order.status.parentid'] = $this->getParentId();
136
		}
137
138
		return $list;
139
	}
140
141
}
142