Passed
Push — master ( 892c73...5dcb5e )
by Aimeos
04:29
created

Standard   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 184
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 184
rs 10
c 0
b 0
f 0
wmc 23

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setAddressId() 0 9 2
A setBaseId() 0 9 2
A setType() 0 11 2
A getBaseId() 0 7 2
A getAddressId() 0 7 2
A __construct() 0 5 1
A copyFrom() 0 8 1
A getType() 0 7 2
B fromArray() 0 18 7
A toArray() 0 13 2
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-2018
7
 * @package MShop
8
 * @subpackage Order
9
 */
10
11
12
namespace Aimeos\MShop\Order\Item\Base\Address;
13
14
15
/**
16
 * Default order address container object
17
 *
18
 * @package MShop
19
 * @subpackage Order
20
 */
21
class Standard
22
	extends \Aimeos\MShop\Order\Item\Base\Address\Base
23
	implements \Aimeos\MShop\Order\Item\Base\Address\Iface
24
{
25
	private $values;
26
27
	/**
28
	 * Initializes the objects with the given array of values.
29
	 *
30
	 * @param array $values List of address elements
31
	 */
32
	public function __construct( array $values = [] )
33
	{
34
		parent::__construct( 'order.base.address.', $values );
35
36
		$this->values = $values;
37
	}
38
39
40
	/**
41
	 * Returns the order base ID the address belongs to.
42
	 *
43
	 * @return string|null Base ID
44
	 */
45
	public function getBaseId()
46
	{
47
		if( isset( $this->values['order.base.address.baseid'] ) ) {
48
			return (string) $this->values['order.base.address.baseid'];
49
		}
50
51
		return null;
52
	}
53
54
55
	/**
56
	 * Sets the order base ID the address belongs to.
57
	 *
58
	 * @param string $value New base ID
59
	 * @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order base address item for chaining method calls
60
	 */
61
	public function setBaseId( $value )
62
	{
63
		if( (string) $value !== $this->getBaseId() )
64
		{
65
			$this->values['order.base.address.baseid'] = (string) $value;
66
			$this->setModified();
67
		}
68
69
		return $this;
70
	}
71
72
73
	/**
74
	 * Returns the original customer address ID.
75
	 *
76
	 * @return string Customer address ID
77
	 */
78
	public function getAddressId()
79
	{
80
		if( isset( $this->values['order.base.address.addressid'] ) ) {
81
			return (string) $this->values['order.base.address.addressid'];
82
		}
83
84
		return '';
85
	}
86
87
88
	/**
89
	 * Sets the original customer address ID.
90
	 *
91
	 * @param string $addrid New customer address ID
92
	 * @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order base address item for chaining method calls
93
	 */
94
	public function setAddressId( $addrid )
95
	{
96
		if( (string) $addrid !== $this->getAddressId() )
97
		{
98
			$this->values['order.base.address.addressid'] = (string) $addrid;
99
			$this->setModified();
100
		}
101
102
		return $this;
103
	}
104
105
106
	/**
107
	 * Returns the address type which can be billing or delivery.
108
	 *
109
	 * @return string Address type
110
	 */
111
	public function getType()
112
	{
113
		if( isset( $this->values['order.base.address.type'] ) ) {
114
			return (string) $this->values['order.base.address.type'];
115
		}
116
117
		return \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY;
118
	}
119
120
121
	/**
122
	 * Sets the new type of the address which can be billing or delivery.
123
	 *
124
	 * @param string $type New type of the address
125
	 * @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order base address item for chaining method calls
126
	 */
127
	public function setType( $type )
128
	{
129
		$this->checkType( $type );
130
131
		if( (string) $type !== $this->getType() )
132
		{
133
			$this->values['order.base.address.type'] = (string) $type;
134
			$this->setModified();
135
		}
136
137
		return $this;
138
	}
139
140
141
	/**
142
	 * Copys all data from a given address item.
143
	 *
144
	 * @param \Aimeos\MShop\Common\Item\Address\Iface $item New address
145
	 * @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order base address item for chaining method calls
146
	 */
147
	public function copyFrom( \Aimeos\MShop\Common\Item\Address\Iface $item )
148
	{
149
		parent::copyFrom( $item );
150
151
		$this->setAddressId( $item->getId() );
152
		$this->setModified();
153
154
		return $this;
155
	}
156
157
158
	/*
159
	 * Sets the item values from the given array and removes that entries from the list
160
	 *
161
	 * @param array &$list Associative list of item keys and their values
162
	 * @param boolean True to set private properties too, false for public only
163
	 * @return \Aimeos\MShop\Order\Item\Base\Address\Iface Order address item for chaining method calls
164
	 */
165
	public function fromArray( array &$list, $private = false )
166
	{
167
		$item = parent::fromArray( $list, $private );
168
169
		foreach( $list as $key => $value )
170
		{
171
			switch( $key )
172
			{
173
				case 'order.base.address.baseid': !$private ?: $item = $item->setBaseId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setBaseId() does not exist on Aimeos\MShop\Common\Item\Address\Base. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Address\Base such as Aimeos\MShop\Order\Item\Base\Address\Standard. ( Ignorable by Annotation )

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

173
				case 'order.base.address.baseid': !$private ?: $item = $item->/** @scrutinizer ignore-call */ setBaseId( $value ); break;
Loading history...
174
				case 'order.base.address.addressid': !$private ?: $item = $item->setAddressId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setAddressId() does not exist on Aimeos\MShop\Common\Item\Address\Base. Did you maybe mean setAddress3()? ( Ignorable by Annotation )

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

174
				case 'order.base.address.addressid': !$private ?: $item = $item->/** @scrutinizer ignore-call */ setAddressId( $value ); break;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
175
				case 'order.base.address.type': $item = $item->setType( $value ); break;
0 ignored issues
show
Bug introduced by
The method setType() does not exist on Aimeos\MShop\Common\Item\Address\Base. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Address\Base such as Aimeos\MShop\Order\Item\Base\Address\Standard. ( Ignorable by Annotation )

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

175
				case 'order.base.address.type': /** @scrutinizer ignore-call */ $item = $item->setType( $value ); break;
Loading history...
176
				default: continue 2;
177
			}
178
179
			unset( $list[$key] );
180
		}
181
182
		return $item;
183
	}
184
185
186
	/**
187
	 * Returns the item values as array.
188
	 *
189
	 * @param boolean True to return private properties, false for public only
190
	 * @return array Associative list of item properties and their values
191
	 */
192
	public function toArray( $private = false )
193
	{
194
		$list = parent::toArray( $private );
195
196
		$list['order.base.address.type'] = $this->getType();
197
198
		if( $private === true )
199
		{
200
			$list['order.base.address.baseid'] = $this->getBaseId();
201
			$list['order.base.address.addressid'] = $this->getAddressId();
202
		}
203
204
		return $list;
205
	}
206
207
}
208