Passed
Push — master ( f52afb...8d8aff )
by Aimeos
04:36
created

Standard::fromArray()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 19
rs 9.9666
c 0
b 0
f 0
cc 4
nc 5
nop 2
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2024
6
 * @package MShop
7
 * @subpackage Customer
8
 */
9
10
11
namespace Aimeos\MShop\Customer\Item\Address;
12
13
14
/**
15
 * Interface for provider common address DTO objects used by the shop.
16
 * @package MShop
17
 * @subpackage Customer
18
 */
19
class Standard
20
	extends \Aimeos\MShop\Common\Item\Address\Standard
21
	implements \Aimeos\MShop\Customer\Item\Address\Iface
22
{
23
	/**
24
	 * Returns the type of the address item.
25
	 *
26
	 * @return string Address type
27
	 */
28
	public function getType() : string
29
	{
30
		return $this->get( 'customer.address.type', 'delivery' );
31
	}
32
33
34
	/**
35
	 * Sets the type of the address item.
36
	 *
37
	 * @param string $type Address type
38
	 * @return \Aimeos\MShop\Customer\Item\Address\Iface Address item for chaining method calls
39
	 */
40
	public function setType( string $type ) : \Aimeos\MShop\Customer\Item\Address\Iface
41
	{
42
		return $this->set( 'customer.address.type', $type );
43
	}
44
45
46
	/*
47
	 * Sets the item values from the given array and removes that entries from the list
48
	 *
49
	 * @param array &$list Associative list of item keys and their values
50
	 * @param bool True to set private properties too, false for public only
51
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Address item for chaining method calls
52
	 */
53
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
54
	{
55
		$item = parent::fromArray( $list, $private );
56
57
		foreach( $list as $idx => $value )
58
		{
59
			$pos = strrpos( $idx, '.' );
60
			$key = $pos ? substr( $idx, $pos + 1 ) : $idx;
61
62
			switch( $key )
63
			{
64
				case '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. 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

64
				case 'type': /** @scrutinizer ignore-call */ $item = $item->setType( $value ); break;
Loading history...
65
				default: continue 2;
66
			}
67
68
			unset( $list[$idx] );
69
		}
70
71
		return $item;
72
	}
73
74
75
	/**
76
	 * Returns the item values as array.
77
	 *
78
	 * @param bool True to return private properties, false for public only
79
	 * @return array Associative list of item properties and their values
80
	 */
81
	public function toArray( bool $private = false ) : array
82
	{
83
		$list = parent::toArray( $private );
84
85
		$list[$this->getPrefix() . 'type'] = $this->getType();
86
87
		return $list;
88
	}
89
}
90