Completed
Push — master ( 24a86a...771b97 )
by Aimeos
10:31
created

Standard   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 303
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 303
rs 9.68
c 0
b 0
f 0
wmc 34
lcom 1
cbo 3

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getSiteId() 0 4 1
A getCode() 0 8 2
A setCode() 0 10 2
A getConfig() 0 8 2
A setConfig() 0 7 1
A getLabel() 0 8 2
A setLabel() 0 10 2
A getLevel() 0 4 1
A getParentId() 0 4 1
A getStatus() 0 8 2
A setStatus() 0 10 2
A getResourceType() 0 4 1
A isAvailable() 0 4 2
A fromArray() 0 19 6
A toArray() 0 18 2
A getChild() 0 4 1
A getChildren() 0 4 1
A hasChildren() 0 4 1
A addChild() 0 3 1
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-2017
7
 * @package MShop
8
 * @subpackage Locale
9
 */
10
11
12
namespace Aimeos\MShop\Locale\Item\Site;
13
14
15
/**
16
 * Default implementation of a Site item.
17
 *
18
 * @package MShop
19
 * @subpackage Locale
20
 */
21
class Standard
22
	extends \Aimeos\MShop\Common\Item\Base
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
23
	implements \Aimeos\MShop\Locale\Item\Site\Iface
24
{
25
	private $children;
26
	private $values;
27
28
	/**
29
	 * Initializes the site object.
30
	 *
31
	 * @param array $values Associative list of item key/value pairs
32
	 * @param array $children List of nodes implementing \Aimeos\MW\Tree\Node\Iface
33
	 */
34
	public function __construct( array $values = [], array $children = [] )
35
	{
36
		\Aimeos\MW\Common\Base::checkClassList( '\\Aimeos\\MShop\\Locale\\Item\\Site\\Iface', $children );
37
		parent::__construct( 'locale.site.', $values );
38
39
		$this->values = $values;
40
		$this->children = $children;
41
	}
42
43
44
	/**
45
	 * Returns the id of the site.
46
	 *
47
	 * @return integer|null Id of the site
48
	 */
49
	public function getSiteId()
50
	{
51
		return (int) $this->getId();
52
	}
53
54
55
	/**
56
	 * Returns the code of the site.
57
	 *
58
	 * @return string Returns the code of the item
59
	 */
60
	public function getCode()
61
	{
62
		if( isset( $this->values['locale.site.code'] ) ) {
63
			return (string) $this->values['locale.site.code'];
64
		}
65
66
		return '';
67
	}
68
69
70
	/**
71
	 * Sets the code of the site.
72
	 *
73
	 * @param string $code The code to set
74
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
75
	 */
76
	public function setCode( $code )
77
	{
78
		if( (string) $code !== $this->getCode() )
79
		{
80
			$this->values['locale.site.code'] = $this->checkCode( $code );
81
			$this->setModified();
82
		}
83
84
		return $this;
85
	}
86
87
88
	/**
89
	 * Returns the config property of the site.
90
	 *
91
	 * @return array Returns the config of the Site
92
	 */
93
	public function getConfig()
94
	{
95
		if( isset( $this->values['locale.site.config'] ) ) {
96
			return (array) $this->values['locale.site.config'];
97
		}
98
99
		return [];
100
	}
101
102
103
	/**
104
	 * Sets the config property of the site.
105
	 *
106
	 * @param array $options Options to be set for the Site
107
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
108
	 */
109
	public function setConfig( array $options )
110
	{
111
		$this->values['locale.site.config'] = $options;
112
		$this->setModified();
113
114
		return $this;
115
	}
116
117
118
	/**
119
	 * Returns the label property of the site.
120
	 *
121
	 * @return string Returns the label of the Site
122
	 */
123
	public function getLabel()
124
	{
125
		if( isset( $this->values['locale.site.label'] ) ) {
126
			return (string) $this->values['locale.site.label'];
127
		}
128
129
		return '';
130
	}
131
132
133
	/**
134
	 * Sets the label property of the site.
135
	 *
136
	 * @param string $label The label of the Site
137
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
138
	 */
139
	public function setLabel( $label )
140
	{
141
		if( (string) $label !== $this->getLabel() )
142
		{
143
			$this->values['locale.site.label'] = (string) $label;
144
			$this->setModified();
145
		}
146
147
		return $this;
148
	}
149
150
151
	/**
152
	 * Returns the level of the item in the tree
153
	 *
154
	 * @return integer Level of the item starting with "0" for the root node
155
	 */
156
	public function getLevel()
157
	{
158
		return 0;
159
	}
160
161
162
	/**
163
	 * Returns the ID of the parent site
164
	 *
165
	 * @return string Unique ID of the parent site
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
166
	 */
167
	public function getParentId()
168
	{
169
		return 0;
170
	}
171
172
173
	/**
174
	 * Returns the status property of the Site.
175
	 *
176
	 * @return integer Returns the status of the Site
177
	 */
178
	public function getStatus()
179
	{
180
		if( isset( $this->values['locale.site.status'] ) ) {
181
			return (int) $this->values['locale.site.status'];
182
		}
183
184
		return 0;
185
	}
186
187
188
	/**
189
	 * Sets status property.
190
	 *
191
	 * @param integer $status The status of the Site
192
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
193
	 */
194
	public function setStatus( $status )
195
	{
196
		if( (int) $status !== $this->getStatus() )
197
		{
198
			$this->values['locale.site.status'] = (int) $status;
199
			$this->setModified();
200
		}
201
202
		return $this;
203
	}
204
205
206
	/**
207
	 * Returns the item type
208
	 *
209
	 * @return string Item type, subtypes are separated by slashes
210
	 */
211
	public function getResourceType()
212
	{
213
		return 'locale/site';
214
	}
215
216
217
	/**
218
	 * Tests if the item is available based on status, time, language and currency
219
	 *
220
	 * @return boolean True if available, false if not
221
	 */
222
	public function isAvailable()
223
	{
224
		return parent::isAvailable() && (bool) $this->getStatus();
225
	}
226
227
228
	/**
229
	 * Sets the item values from the given array.
230
	 *
231
	 * @param array $list Associative list of item keys and their values
232
	 * @return array Associative list of keys and their values that are unknown
233
	 */
234
	public function fromArray( array $list )
235
	{
236
		$unknown = [];
237
		$list = parent::fromArray( $list );
238
239
		foreach( $list as $key => $value )
240
		{
241
			switch( $key )
242
			{
243
				case 'locale.site.code': $this->setCode( $value ); break;
244
				case 'locale.site.label': $this->setLabel( $value ); break;
245
				case 'locale.site.config': $this->setConfig( $value ); break;
246
				case 'locale.site.status': $this->setStatus( $value ); break;
247
				default: $unknown[$key] = $value;
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
248
			}
249
		}
250
251
		return $unknown;
252
	}
253
254
255
	/**
256
	 * Returns the item values as array.
257
	 *
258
	 * @param boolean True to return private properties, false for public only
259
	 * @return array Associative list of item properties and their values
260
	 */
261
	public function toArray( $private = false )
262
	{
263
		$list = parent::toArray( $private );
264
265
		$list['locale.site.code'] = $this->getCode();
266
		$list['locale.site.label'] = $this->getLabel();
267
		$list['locale.site.config'] = $this->getConfig();
268
		$list['locale.site.status'] = $this->getStatus();
269
		$list['locale.site.hasChildren'] = $this->hasChildren();
270
271
		if( $private === true )
272
		{
273
			$list['locale.site.level'] = $this->getLevel();
274
			$list['locale.site.parentid'] = $this->getParentId();
275
		}
276
277
		return $list;
278
	}
279
280
281
	/**
282
	 * Returns a child of this node identified by its index.
283
	 *
284
	 * @param integer $index Index of child node
285
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Selected node
286
	 */
287
	public function getChild( $index )
288
	{
289
		throw new \Aimeos\MShop\Locale\Exception( sprintf( 'Child node with index "%1$d" not available', $index ) );
290
	}
291
292
293
	/**
294
	 * Returns all children of this node.
295
	 *
296
	 * @return array Numerically indexed list of nodes
297
	 */
298
	public function getChildren()
299
	{
300
		return [];
301
	}
302
303
304
	/**
305
	 * Tests if a node has children.
306
	 *
307
	 * @return boolean True if node has children, false if not
308
	 */
309
	public function hasChildren()
310
	{
311
		return false;
312
	}
313
314
315
	/**
316
	 * Adds a child node to this node.
317
	 *
318
	 * @param \Aimeos\MShop\Common\Item\Tree\Iface $item Child node to add
319
	 */
320
	public function addChild( \Aimeos\MShop\Common\Item\Tree\Iface $item )
321
	{
322
	}
323
}