Passed
Push — master ( ae8cc8...b4d665 )
by Aimeos
04:50
created

Standard   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 20
c 1
b 0
f 0
dl 0
loc 102
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getLabel() 0 3 1
A setLabel() 0 3 1
A __construct() 0 3 1
A setCode() 0 3 1
A getCode() 0 3 1
A fromArray() 0 17 4
A toArray() 0 8 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2023
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
	 * Initializes the group item
26
	 *
27
	 * @param array $values List of key/value pairs of the group
28
	 */
29
	public function __construct( array $values = [] )
30
	{
31
		parent::__construct( 'group.', $values );
32
	}
33
34
35
	/**
36
	 * Returns the code of the group
37
	 *
38
	 * @return string Code of the group
39
	 */
40
	public function getCode() : string
41
	{
42
		return $this->get( 'group.code', '' );
43
	}
44
45
46
	/**
47
	 * Sets the new code of the group
48
	 *
49
	 * @param string $value Code of the group
50
	 * @return \Aimeos\MShop\Group\Item\Iface Customer group item for chaining method calls
51
	 */
52
	public function setCode( string $value ) : \Aimeos\MShop\Group\Item\Iface
53
	{
54
		return $this->set( 'group.code', $value );
55
	}
56
57
58
	/**
59
	 * Returns the label of the group
60
	 *
61
	 * @return string Label of the group
62
	 */
63
	public function getLabel() : string
64
	{
65
		return $this->get( 'group.label', '' );
66
	}
67
68
69
	/**
70
	 * Sets the new label of the group
71
	 *
72
	 * @param string $value Label of the group
73
	 * @return \Aimeos\MShop\Group\Item\Iface Customer group item for chaining method calls
74
	 */
75
	public function setLabel( string $value ) : \Aimeos\MShop\Group\Item\Iface
76
	{
77
		return $this->set( 'group.label', $value );
78
	}
79
80
81
	/*
82
	 * Sets the item values from the given array and removes that entries from the list
83
	 *
84
	 * @param array &$list Associative list of item keys and their values
85
	 * @param bool True to set private properties too, false for public only
86
	 * @return \Aimeos\MShop\Group\Item\Iface Group item for chaining method calls
87
	 */
88
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
89
	{
90
		$item = parent::fromArray( $list, $private );
91
92
		foreach( $list as $key => $value )
93
		{
94
			switch( $key )
95
			{
96
				case 'group.code': $item = $item->setCode( $value ); break;
97
				case 'group.label': $item = $item->setLabel( $value ); break;
98
				default: continue 2;
99
			}
100
101
			unset( $list[$key] );
102
		}
103
104
		return $item;
105
	}
106
107
108
	/**
109
	 * Returns the item values as array.
110
	 *
111
	 * @param bool True to return private properties, false for public only
112
	 * @return array Associative list of item properties and their values
113
	 */
114
	public function toArray( bool $private = false ) : array
115
	{
116
		$list = parent::toArray( $private );
117
118
		$list['group.code'] = $this->getCode();
119
		$list['group.label'] = $this->getLabel();
120
121
		return $list;
122
	}
123
}
124