Passed
Push — master ( 7b7538...994c79 )
by Aimeos
05:04
created

Standard::setCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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\Group\Item;
12
13
14
/**
15
 * Default group object
16
 *
17
 * @package MShop
18
 * @subpackage Customer
19
 */
20
class Standard
21
	extends \Aimeos\MShop\Common\Item\Base
22
	implements \Aimeos\MShop\Group\Item\Iface
23
{
24
	/**
25
	 * Returns the code of the group
26
	 *
27
	 * @return string Code of the group
28
	 */
29
	public function getCode() : string
30
	{
31
		return $this->get( 'group.code', '' );
32
	}
33
34
35
	/**
36
	 * Sets the new code of the group
37
	 *
38
	 * @param string $value Code of the group
39
	 * @return \Aimeos\MShop\Group\Item\Iface Customer group item for chaining method calls
40
	 */
41
	public function setCode( string $value ) : \Aimeos\MShop\Group\Item\Iface
42
	{
43
		return $this->set( 'group.code', $value );
44
	}
45
46
47
	/**
48
	 * Returns the label of the group
49
	 *
50
	 * @return string Label of the group
51
	 */
52
	public function getLabel() : string
53
	{
54
		return $this->get( 'group.label', '' );
55
	}
56
57
58
	/**
59
	 * Sets the new label of the group
60
	 *
61
	 * @param string $value Label of the group
62
	 * @return \Aimeos\MShop\Group\Item\Iface Customer group item for chaining method calls
63
	 */
64
	public function setLabel( string $value ) : \Aimeos\MShop\Group\Item\Iface
65
	{
66
		return $this->set( 'group.label', $value );
67
	}
68
69
70
	/*
71
	 * Sets the item values from the given array and removes that entries from the list
72
	 *
73
	 * @param array &$list Associative list of item keys and their values
74
	 * @param bool True to set private properties too, false for public only
75
	 * @return \Aimeos\MShop\Group\Item\Iface Group item for chaining method calls
76
	 */
77
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
78
	{
79
		$item = parent::fromArray( $list, $private );
80
81
		foreach( $list as $key => $value )
82
		{
83
			switch( $key )
84
			{
85
				case 'group.code': $item = $item->setCode( $value ); break;
86
				case 'group.label': $item = $item->setLabel( $value ); break;
87
				default: continue 2;
88
			}
89
90
			unset( $list[$key] );
91
		}
92
93
		return $item;
94
	}
95
96
97
	/**
98
	 * Returns the item values as array.
99
	 *
100
	 * @param bool True to return private properties, false for public only
101
	 * @return array Associative list of item properties and their values
102
	 */
103
	public function toArray( bool $private = false ) : array
104
	{
105
		$list = parent::toArray( $private );
106
107
		$list['group.code'] = $this->getCode();
108
		$list['group.label'] = $this->getLabel();
109
110
		return $list;
111
	}
112
}
113