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

Standard::fromArray()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 6
nop 1
dl 0
loc 19
rs 9.0111
c 0
b 0
f 0
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 MAdmin
8
 * @subpackage Log
9
 */
10
11
12
namespace Aimeos\MAdmin\Log\Item;
13
14
15
/**
16
 * Default log item implementation.
17
 *
18
 * @package MAdmin
19
 * @subpackage Log
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\MAdmin\Log\Item\Iface
24
{
25
	private $values;
26
27
	/**
28
	 * Initializes the log item.
29
	 *
30
	 * @param array $values Associative list of key/value pairs
31
	 */
32
	public function __construct( array $values = [] )
33
	{
34
		parent::__construct( 'log.', $values );
35
36
		$this->values = $values;
37
	}
38
39
40
	/**
41
	 * Returns the facility of the item.
42
	 *
43
	 * @return string Returns the facility
44
	 */
45
	public function getFacility()
46
	{
47
		if( isset( $this->values['log.facility'] ) ) {
48
			return (string) $this->values['log.facility'];
49
		}
50
51
		return '';
52
	}
53
54
55
	/**
56
	 * Sets the new facility of the of the item.
57
	 *
58
	 * @param string $facility Facility
59
	 * @return \Aimeos\MAdmin\Log\Item\Iface Log item for chaining method calls
60
	 */
61
	public function setFacility( $facility )
62
	{
63
		if( (string) $facility !== $this->getFacility() )
64
		{
65
			$this->values['log.facility'] = (string) $facility;
66
			$this->setModified();
67
		}
68
69
		return $this;
70
	}
71
72
73
	/**
74
	 * Returns the timestamp of the item.
75
	 *
76
	 * @return string|null ISO date in YYYY-MM-DD hh:mm:ss format
77
	 */
78
	public function getTimestamp()
79
	{
80
		if( isset( $this->values['log.timestamp'] ) ) {
81
			return (string) $this->values['log.timestamp'];
82
		}
83
	}
84
85
86
	/**
87
	 * Returns the priority of the item.
88
	 *
89
	 * @return integer Returns the priority
90
	 */
91
	public function getPriority()
92
	{
93
		if( isset( $this->values['log.priority'] ) ) {
94
			return (int) $this->values['log.priority'];
95
		}
96
97
		return 0;
98
	}
99
100
101
	/**
102
	 * Sets the new priority of the item.
103
	 *
104
	 * @param integer $priority Priority
105
	 * @return \Aimeos\MAdmin\Log\Item\Iface Log item for chaining method calls
106
	 */
107
	public function setPriority( $priority )
108
	{
109
		if( (int) $priority !== $this->getPriority() )
110
		{
111
			$this->values['log.priority'] = (int) $priority;
112
			$this->setModified();
113
		}
114
115
		return $this;
116
	}
117
118
119
	/**
120
	 * Returns the message of the item.
121
	 *
122
	 * @return string Returns the message
123
	 */
124
	public function getMessage()
125
	{
126
		if( isset( $this->values['log.message'] ) ) {
127
			return (string) $this->values['log.message'];
128
		}
129
130
		return '';
131
	}
132
133
134
	/**
135
	 * Sets the new message of the item.
136
	 *
137
	 * @param string $message Message
138
	 * @return \Aimeos\MAdmin\Log\Item\Iface Log item for chaining method calls
139
	 */
140
	public function setMessage( $message )
141
	{
142
		if( (string) $message !== $this->getMessage() )
143
		{
144
			$this->values['log.message'] = (string) $message;
145
			$this->setModified();
146
		}
147
148
		return $this;
149
	}
150
151
152
	/**
153
	 * Returns the request of the item.
154
	 *
155
	 * @return string Returns the request
156
	 */
157
	public function getRequest()
158
	{
159
		if( isset( $this->values['log.request'] ) ) {
160
			return (string) $this->values['log.request'];
161
		}
162
163
		return '';
164
	}
165
166
167
	/**
168
	 * Sets the new request of the item.
169
	 *
170
	 * @param string $request Request
171
	 * @return \Aimeos\MAdmin\Log\Item\Iface Log item for chaining method calls
172
	 */
173
	public function setRequest( $request )
174
	{
175
		if( (string) $request !== $this->getRequest() )
176
		{
177
			$this->values['log.request'] = (string) $request;
178
			$this->setModified();
179
		}
180
181
		return $this;
182
	}
183
184
185
	/**
186
	 * Returns the item type
187
	 *
188
	 * @return string Item type, subtypes are separated by slashes
189
	 */
190
	public function getResourceType()
191
	{
192
		return 'log';
193
	}
194
195
196
	/**
197
	 * Sets the item values from the given array.
198
	 *
199
	 * @param array $list Associative list of item keys and their values
200
	 * @return array Associative list of keys and their values that are unknown
201
	 */
202
	public function fromArray( array $list )
203
	{
204
		$unknown = [];
205
		$list = parent::fromArray( $list );
206
207
		foreach( $list as $key => $value )
208
		{
209
			switch( $key )
210
			{
211
				case 'log.facility': $this->setFacility( $value ); break;
212
				case 'log.priority': $this->setPriority( $value ); break;
213
				case 'log.message': $this->setMessage( $value ); break;
214
				case 'log.request': $this->setRequest( $value ); break;
215
				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...
216
			}
217
		}
218
219
		return $unknown;
220
	}
221
222
223
	/**
224
	 * Returns the item values as array.
225
	 *
226
	 * @param boolean True to return private properties, false for public only
227
	 * @return array Associative list of item properties and their values
228
	 */
229
	public function toArray( $private = false )
230
	{
231
		$list = parent::toArray( $private );
232
233
		$list['log.facility'] = $this->getFacility();
234
		$list['log.timestamp'] = $this->getTimestamp();
235
		$list['log.priority'] = $this->getPriority();
236
		$list['log.message'] = $this->getMessage();
237
		$list['log.request'] = $this->getRequest();
238
239
		return $list;
240
	}
241
}
242